Repository navigation
KNOX-1997: Adding changes to buffer messages from backend in onMessag… - #143
Conversation
There was a problem hiding this comment.
So I don't know this code, but it seems weird to me that getRemote returns null at all. It looks like the remote null check is fixing the symptom not the root cause. Is it possible to make getRemote block and never return null? I think that would avoid having to buffer messages at all?
There was a problem hiding this comment.
What I observed that remote was being created in other thread which was executing onWebSocketConnect() while this current thread received a message. This might be an limitation with Jetty itself, check: signalapp/Signal-Desktop#1840.
I checked jetty examples and even there the server is using locks before accessing remote, as mentioned in the above link.
There was a problem hiding this comment.
I prefer to avoid locks if they can be avoided. Instead of buffering can we wait for a configurable amount of time to see if the remote object is created before quitting ? This should not be an issue IMO since this should be on a different thread than other connections.
There was a problem hiding this comment.
I tried adding a fixed delay of few seconds in onMessageText() API but I was still seeing the issue in some cases. So adding a fixed configurable delay will not work. I aslo want to avoid locks as they incur a performance overhead. IF you have any suggestions on how can locks be avoided, let me know. Thanks.
moresandeep
left a comment
There was a problem hiding this comment.
Thanks @goelrajat, the patch is on track, we requested few changes. The concerning one is about Locks, if we can avoid them that would be great. there are callback functions, not sure of we can leverage them but it would be good to try them out ! Thanks again for the patch and for finding and troubleshooting it !
There was a problem hiding this comment.
I don't like a locks here, can they be avoided, e.g. by using configurable wait in public void onMessageText(String message, Object session) { not sure if this is optimal, this is the first thing that came to my mind.
There was a problem hiding this comment.
I tried adding a fixed delay of few seconds but I was still seeing the issue in some cases. So delay is unpredictable.
There was a problem hiding this comment.
Lock in a callback seems like a bad idea, especially the lock is dependent on the creation of the front end session. Is there a way to avoid locks ?
There was a problem hiding this comment.
I could not think of any other way, haven't worked much with Jetty. If you can provide any pointers, I will be happy to try things out.
There was a problem hiding this comment.
I prefer to avoid locks if they can be avoided. Instead of buffering can we wait for a configurable amount of time to see if the remote object is created before quitting ? This should not be an issue IMO since this should be on a different thread than other connections.
There was a problem hiding this comment.
This should probably go inside of try{ in case getRemote() throws an exception.
|
Any updates on whether this PR can be merged or something more needs to be done here. |
|
@goelrajat you might have to rebase your commit on latest master to get Travis builds to pass. Just pushed a build fix a few minutes ago. I'll leave it to @smolnar82 and @moresandeep to review |
|
@risdenk Rebase has no impact:
|
|
Your master is behind First, you need to pull changes from |
aa831f4 to
990b36c
Compare
|
@smolnar82 Done. Thanks |
|
One more thing: since you added a new configuration in |
|
@goelrajat - tests are failing: |
|
@smolnar82 Test case is passing on my local build setup. However, I have increased timeout now and updated the test case. Hopefully, should work now. Raised a ticket for documentation: https://issues.apache.org/jira/browse/KNOX-2019 |
|
@goelrajat - tests are failing again: Before you submit a new patch could you please run the following command locally: |
risdenk
left a comment
There was a problem hiding this comment.
@moresandeep / @smolnar82 any other comments about this?
|
Nope; works for me now! |
moresandeep
left a comment
There was a problem hiding this comment.
@goelrajat apologies for the delay, I think I am ok with the locks. I can't think of a better way to do it right now and don't want to hold up the patch for it. I requested few changes on the unit tests, once we have that the patch is good to go (I'll do some internal testing as well to make sure we don't break anything).
Thanks again !
|
Travis build failed due to failure in test case WebsocketServerInitiatedMessageTest, however the same test case is passing on my local setup. I tried multiple times but it works on my side. bash-3.2$ mvn test -Dtest=org.apache.knox.gateway.websockets.WebsocketServerInitiatedMessageTest Can someone please check? |
…eText() if frontend session related data structures have not been setup i.e. remote is null. Message buffer will be flushed when remote is set by other thread executing onWebSocketConnect() API. To synchronise reading/flushing buffer, added a lock
…gument to constructor
…assing on local setup
…assing on local setup
1387489 to
6dcfdcb
Compare
|
Test case changes have been done. Please check and merge. |
|
LGTM +1 |
|
@moresandeep Please check and merge this one as well. |
|
@moresandeep Can you please merge this PR? I want to raise another PR for KNOX-2004 and its changes are dependent on this PR. |
@goelrajat I will get to it probably mid next week, since this is pretty involved and touches a bunch of things I would like to test it thoroughly. |
|
@moresandeep any update here? |
|
Still underwater, hoping to find some time by the end of this week. |
|
Any updates on this one please? When can we merge this ? Its been idle for too long now. |
moresandeep
left a comment
There was a problem hiding this comment.
Looks good, sorry for the delay in reviewing.

What changes were proposed in this pull request?
Adding changes to buffer messages from backend in onMessageText() if frontend session related data structures have not been setup i.e. remote is null. Message buffer will be flushed when remote is set by other thread executing onWebSocketConnect() API. To synchronize reading/flushing buffer, added a lock
How was this patch tested?
Race condition was easily reproducible with our service UI and backedn when integrated with Knox. After this change, I no longer see the NullPointerException. Since this is a race condition, its hard to add a unit test case for it. In my case, the race condition was getting hit when service backend used to send a data frame immediately after opening a websocket connection but Knox hadn't setup the connection related data structures. So I added a test case for scenario where send a message to frontend while opening a websocket.