-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove a race condition from the WebSocket upgrade
An upgrade to WebSocket invokes three handlers in an order. First, the `shouldUpgrade` handler supplied by the user is run to decide if an upgrade must go through. This handler also supplies additional headers to be sent in the response. Next, after the WebSocket upgrader is done upgrading the pipeline, the `completionHandler` is called. We remove Kitura-NIO's `HTTPRequestHandler` here. Next, the `upgradePipelineHandler` is invoked. This handler allows us to add all the WebSocket related `ChannelHandler`s. For an undocumented reason, we saved the `ChannelHandlerContext` received by the `completionHandler` in the `HTTPServer` and later used it upgrade the pipeline in `upgradePipelineHandler`. This can easily lead to a race condition where we saved the `ChannelHandlerContext` for a connection, into the `HTTPServer` but before it could be used in `upgradePipelineHandler`, it was overwritten by the upgrade happening on another connection. Consequently, we never upgraded the pipeline of the former connection. This could lead to different kinds of failures. The `upgradePipelineHandler` has `Channel` as one of its parameters. Hence there is no need to store the `ChannelHandlerContext` for use in this closure. Consequently, we have to use a `Channel` to initialize an `HTTPServerRequest`, which, in turn, is modified to accept a `Channel` instead of a `ChannelHandlerContext`.
- Loading branch information
Pushkar Kulkarni
committed
Jul 22, 2019
1 parent
dfdbff2
commit 09b88f8
Showing
3 changed files
with
16 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters