#vulnerable code 
                                public void close() {
        if (!closed) {
            synchronized (lock) {
                if (!closed) {
                    try {
                        log.info("Closing session");
                        Channel[] channelToClose = channels.values().toArray(new Channel[0]);
                        for (Channel channel : channelToClose) {
                            log.debug("Closing channel {}", channel.getId());
                            IoUtils.closeQuietly(channel);
                        }
                        log.debug("Closing IoSession");
                        CloseFuture future = ioSession.close();
                        log.debug("Waiting for IoSession to be closed");
                        future.join();
                        log.debug("IoSession closed");
                    } catch (Throwable t) {
                        log.warn("Error closing session", t);
                    }
                    closed = true;
                    lock.notifyAll();
                }
            }
        }
    } 
                            #location 2 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                public void close() {
        if (!closed) {
            synchronized (lock) {
                if (!closed && !closing) {
                    try {
                        closing = true;
                        log.info("Closing session");
                        Channel[] channelToClose = channels.values().toArray(new Channel[0]);
                        for (Channel channel : channelToClose) {
                            log.debug("Closing channel {}", channel.getId());
                            IoUtils.closeQuietly(channel);
                        }
                        log.debug("Closing IoSession");
                        CloseFuture future = ioSession.close(true);
                        future.addListener(new IoFutureListener() {
                            public void operationComplete(IoFuture future) {
                                synchronized (lock) {
                                    log.debug("IoSession closed");
                                    closed = true;
                                    lock.notifyAll();
                                }
                            }
                        });
                    } catch (Throwable t) {
                        log.warn("Error closing session", t);
                    }
                }
            }
        }
    }