Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception occured while removing the inactive WebSocket ChannelContexts #1551

Closed
sajith-madhusanka opened this issue Mar 3, 2023 · 0 comments

Comments

@sajith-madhusanka
Copy link

sajith-madhusanka commented Mar 3, 2023

Description

The following error is getting printed constantly in the wso2carbon.log when performing the performance test on WebSocket APIs.

[2023-02-24 20:14:48,126] ERROR - InboundWebsocketSourceHandler Exception occured while injecting websocket frames to the Synapse engine
java.lang.NullPointerException: null

Steps to Reproduce

  • Created mock WebSocket backed-end using tornado 1 ( python ) which echoes back
import tornado.httpserver
import tornado.websocket
import tornado.ioloop
import tornado.web
import socket
'''
This is a simple Websocket Echo server that uses the Tornado websocket handler.
Please run `pip install tornado` with python of version 2.7.9 or greater to install tornado.
This program will echo back the reverse of whatever it recieves.
Messages are output to the terminal for debuggin purposes. 
''' 
 
class WSHandler(tornado.websocket.WebSocketHandler):
    def open(self):
        print ('new connection')
      
    def on_message(self, message):
        print ('message received:  ',message)
        #print ('sending back message: ' % message[::-1])
        self.write_message(message)
 
 
application = tornado.web.Application([
    (r'/ws', WSHandler),
])
 
 
if __name__ == '__main__':
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(8888)
    myIP = socket.gethostbyname(socket.gethostname())
    print ('** Websocket Server Started at **' ,myIP)
    tornado.ioloop.IOLoop.instance().start()
  • Deployed a WebSocket API with the aforementioned BE endpoint ( ws://localhost:8888/ws )

  • Conducted a load test by invoking the WebSocket endpoint by executing the below script in parallel and we could notice the above error trace a few times in the wso2carbon log after executing the script for a few minutes ( ~ 10 minutes ).

#!/bin/bash
for i in `seq 1 3000`
do  
 echo "Looping ... number $i";  
 wscat --connect ws://localhost:9099/testws/1.0?access_token=<JWT_TOKEN> -w 1 -x '{ "hello" : "world"}';
done | tee test_wscat_out.txt

Affected Component

APIM

Version

3.2.0

Environment Details (with versions)

No response

Relevant Log Output

TID: [-1234] [] [2023-03-03 16:04:23,678] ERROR {org.wso2.carbon.inbound.endpoint.protocol.websocket.InboundWebsocketSourceHandler} - Exception occured while injecting websocket frames to the Synapse engine java.lang.NullPointerException
	at org.wso2.carbon.inbound.endpoint.protocol.websocket.management.WebsocketSubscriberPathManager.removeChannelContext(WebsocketSubscriberPathManager.java:79)
	at org.wso2.carbon.inbound.endpoint.protocol.websocket.InboundWebsocketSourceHandler.handleClientWebsocketChannelTermination(InboundWebsocketSourceHandler.java:571)
	at org.wso2.carbon.inbound.endpoint.protocol.websocket.InboundWebsocketSourceHandler.handleWebSocketFrame(InboundWebsocketSourceHandler.java:393)
	at org.wso2.carbon.inbound.endpoint.protocol.websocket.InboundWebsocketSourceHandler.channelRead(InboundWebsocketSourceHandler.java:167)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
	at org.wso2.carbon.apimgt.gateway.handlers.WebsocketInboundHandler.channelRead_aroundBody4(WebsocketInboundHandler.java:298)
	at org.wso2.carbon.apimgt.gateway.handlers.WebsocketInboundHandler.channelRead(WebsocketInboundHandler.java:155)
	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:834)

Related Issues

No response

Suggested Labels

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants