zhouhailin / freeswitch-externals

FreeSWITCH externals projects
https://zhouhailin.github.io/freeswitch-externals/
Apache License 2.0
163 stars 83 forks source link

同步调用时,单线程池因为服务端异常,请求一直阻塞 #28

Closed zhangjicai2016 closed 1 year ago

zhangjicai2016 commented 1 year ago

单线程池调用link.thingscloud.freeswitch.esl.inbound.handler.InboundChannelHandler#sendSyncSingleLineCommand方法时,如果服务端挂了或者重启了一直收不到响应时,这个线程会一直阻塞

public EslMessage sendSyncSingleLineCommand(final String command) {
        if (isTraceEnabled) {
            log.trace("sendSyncSingleLineCommand command : {}", command);
        }
        SyncCallback callback = new SyncCallback();
        syncLock.lock();
        try {
            syncCallbacks.add(callback);
            channel.writeAndFlush(command + MESSAGE_TERMINATOR);
        } finally {
            syncLock.unlock();
        }
        return callback.get();
    }

callback.get()方法一直在等待返回,link.thingscloud.freeswitch.esl.inbound.handler.InboundChannelHandler.SyncCallback中的get方法中的latch.await()这个方法是否可以设置一个等待超时

 /**
         * Block waiting for the countdown latch to be released, then return the
         * associated response object.
         *
         * @return msg
         */
        EslMessage get() {
            try {
                log.trace("awaiting latch ... ");
                latch.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            log.trace("returning response [{}]", response);
            return response;
        }
zhouhailin commented 1 year ago

由于esl机制问题,同步调用的确存在该问题,建议采用异步调用,上述问题小概率性出现

针对该问题,感觉在连接断开时,将syncCallbacks里面元素都unlock,比较合适

zhouhailin commented 1 year ago

应该不会出现这样的,如果链接断开后InboundChannelHandler对象会销毁的