WebsocketServerTransport bind does not resolve when given a WebsocketServer which leverages an listening http.Server instance #237
Labels
1.0
Pullrequests & issues related to the Typescript rewrite and 1.0 release
enhancement
Suggests, requests, or implements a feature or enhancement
As described below, when calling
bind
on aWebsocketServerTransport
created with aWebsocketServer
that uses a listeninghttp.Server
, thebind
call never resolves.------- Original comment body:
Hi @viglucci, I'm finally getting around to integrating RSocket 1.0 in a greenfield project, so I'll be adding to this thread as and when I find anything worth sharing.
So far loving the simple integration with RxJS, particularly on the client side this has reduced our RSocket setup code by at least 10x. Great work on that.
I had one small hiccup that I've had to hack around on the server side. We're running an Express server with some "normal" HTTP endpoints, and we want RSocket to only listen on a
/subscriptions
URL. The way we're doing this is:We have an existing
httpServer: http.Server
, and my initial instinct was to instantiate the transport like this:We were calling this as follows in our server setup code:
This didn't work though, as
rsocketServer.bind()
never resolves.I noticed that
WebsocketServerTransport#connectServer
uses thelistening
event to resolve the server:rsocket-js/packages/rsocket-websocket-server/src/WebsocketServerTransport.ts
Line 108 in c6d6c47
Manually adding
websocketServer.addListener('listening', () => console.log('I am listening'))
, and also adding'connection'
listeners showed me that the WebSocket server was listening correctly.Instantiating the
WebSocket.Server
inside thewsCreator
callback did not help either.WebSocket.Server
just binds to the HTTP server'slistening
event (code), so this never emits if the server is already listening.I can fix this for now by instantiating the RSocket server before listening on the HTTP server, eg.:
...but it's a bit confusing that the order makes a difference.
I can see why we'd want to await the
listening
event insideconnectServer
, but is there potentially some way of checking whether theWebSocket.Server
is already listening and immediately resolving if so?Anyway not a blocker at all, just a papercut :)
Will report on more as I come across it & once again thanks a lot for working on this!
Originally posted by @lachenmayer in #158 (comment)
The text was updated successfully, but these errors were encountered: