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

Websocket support broken #738

Closed
CorentinDoue opened this issue Jul 8, 2019 · 7 comments
Closed

Websocket support broken #738

CorentinDoue opened this issue Jul 8, 2019 · 7 comments
Labels

Comments

@CorentinDoue
Copy link

Hi I was using the websocket support directly from the development branch :

//package.json
"scripts": {
   "start": "sls offline start --useWebsocket"
},
"devDependencies": {
    "serverless-offline": "git://github.com/dherault/serverless-offline.git#websocket-fixes",
}
//serverless.yml
service:
  name: ${env:SERVICE_NAME}

plugins:
  - serverless-plugin-typescript
  - serverless-plugin-optimize
  - serverless-dynamodb-local
  - serverless-offline-sns
  - serverless-dotenv-plugin
  - serverless-offline

custom:
  serverless-offline:
    host: 0.0.0.0
    port: 4000
    websocketPort: 4001

  dynamodb:
    stages:
      - development
    start:
      host: dynamodb # or the name of your Dynamo docker container
      port: "8000" # the port of our Dynamo docker container
      noStart: true
      migrate: true

  serverless-offline-sns:
    port: 4002

I use docker (with node:10) so I need to set the host to 0.0.0.0 instead of localhost.

Everything worked fine.

But today I switched to the current version of serverless-offline (v.5.7.1) and the websockets don't work any more.

  • From my front-end the websocket is open and don't close
  • The $connect and $disconnect events do not trigger the lambda which listen them.
  • None of the messages through $default trigger my lambda.
  • I have this error for each message through $default:
Serverless: Starting Offline: development/eu-west-3.                                                                                                                                               
                                                                                                                                                                                                   
Serverless: Routes for api:                                                                                                                                                                        
Serverless: ANY /{proxy*}                                                                                                                                                                          
Serverless: POST /{apiVersion}/functions/caspr-serverless-development-api/invocations                                                                                                              
                                                                                                                                                                                                   
Serverless: Routes for pubsub:                                                                                                                                                                     
WebSocket support in serverless-offline is experimental.                                                                                                                                           
For any bugs, missing features or other feedback file an issue at https://github.com/dherault/serverless-offline/issues                                                                            
Serverless: Action '$connect'                                                                                                                                                                      
Serverless: Action '$disconnect'                                                                                                                                                                   
Serverless: POST /{apiVersion}/functions/caspr-serverless-development-pubsub/invocations                                                                                                           
                                                                                                                                                                                                   
Serverless: Routes for wsdefault:                                                                                                                                                                  
Serverless: Action '$default'                                                                                                                                                                      
Serverless: POST /{apiVersion}/functions/caspr-serverless-development-wsdefault/invocations                                                                                                        
                                                                                                                                                                                                   
Serverless: Offline [HTTP] listening on http://0.0.0.0:4000                                                                                                                                        
Serverless: Enter "rp" to replay the last request                                                                                                                                                  
                                                                                                                                                                                                   
Serverless: Offline [websocket] listening on ws://0.0.0.0:4001                                                                                                                                     
(node:17) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_URL]: Invalid URL: /                                                                                                            
    at onParseError (internal/url.js:241:17)                                                                                                                                                       
    at new URL (internal/url.js:319:5)                                                                                                                                                             
    at Object.connect (/app/node_modules/serverless-offline/src/ApiGatewayWebSocket.js:174:40)                                                                                                     
    at WebSocketServer.wss.on (/app/node_modules/hapi-plugin-websocket/hapi-plugin-websocket.js:209:34)                                                                                            
    at WebSocketServer.emit (events.js:198:13)                                                                                                                                                     
    at WebSocketServer.EventEmitter.emit (domain.js:448:20)                                                                                                                                        
    at handleUpgrade (/app/node_modules/hapi-plugin-websocket/node_modules/ws/lib/websocket-server.js:90:18)                                                                                       
    at WebSocketServer.completeUpgrade (/app/node_modules/hapi-plugin-websocket/node_modules/ws/lib/websocket-server.js:321:5)                                                                     
    at options.verifyClient (/app/node_modules/hapi-plugin-websocket/node_modules/ws/lib/websocket-server.js:237:16)                                                                               
    at Object.verifyClient (/app/node_modules/hapi-plugin-websocket/hapi-plugin-websocket.js:142:21)                                                                                               
    at WebSocketServer.handleUpgrade (/app/node_modules/hapi-plugin-websocket/node_modules/ws/lib/websocket-server.js:232:22)                                                                      
    at Server.upgrade (/app/node_modules/hapi-plugin-websocket/node_modules/ws/lib/websocket-server.js:89:16)                                                                                      
    at Server.emit (events.js:198:13)                                                                                                                                                              
    at Server.EventEmitter.emit (domain.js:448:20)                                                                                                                                                 
    at onParserExecuteCommon (_http_server.js:553:14)                                                                                                                                              
    at onParserExecute (_http_server.js:499:3)                                                                                                                                                     
(node:17) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without
 a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

The http routes are still ok.

I retried to switch back to

"serverless-offline": "git://github.com/dherault/serverless-offline.git#websocket-fixes"

It fixes the issue, so I will continue to use it.

Thank you :)

@dherault
Copy link
Owner

dherault commented Jul 8, 2019

Will be fixed in minutes!

@dherault
Copy link
Owner

dherault commented Jul 8, 2019

v5.7.2

@CorentinDoue
Copy link
Author

Thank you, that was quick but the PR #735 don't fix all the error for me :

backend_1     | Serverless: Offline [websocket] listening on ws://0.0.0.0:4001                                                                                                                                     
backend_1     | (node:17) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object                                                                                                  
backend_1     |     at Function.keys (<anonymous>)                                                                                                                                                                 
backend_1     |     at Object.connect (/app/node_modules/serverless-offline/src/ApiGatewayWebSocket.js:199:26)                                                                                                     
backend_1     |     at WebSocketServer.wss.on (/app/node_modules/hapi-plugin-websocket/hapi-plugin-websocket.js:209:34)                                                                                            
backend_1     |     at WebSocketServer.emit (events.js:198:13)                                                                                                                                                     
backend_1     |     at WebSocketServer.EventEmitter.emit (domain.js:448:20)                                                                                                                                        
backend_1     |     at handleUpgrade (/app/node_modules/hapi-plugin-websocket/node_modules/ws/lib/websocket-server.js:90:18)                                                                                       
backend_1     |     at WebSocketServer.completeUpgrade (/app/node_modules/hapi-plugin-websocket/node_modules/ws/lib/websocket-server.js:321:5)                                                                     
backend_1     |     at options.verifyClient (/app/node_modules/hapi-plugin-websocket/node_modules/ws/lib/websocket-server.js:237:16)                                                                               
backend_1     |     at Object.verifyClient (/app/node_modules/hapi-plugin-websocket/hapi-plugin-websocket.js:142:21)                                                                                               
backend_1     |     at WebSocketServer.handleUpgrade (/app/node_modules/hapi-plugin-websocket/node_modules/ws/lib/websocket-server.js:232:22)                                                                      
backend_1     |     at Server.upgrade (/app/node_modules/hapi-plugin-websocket/node_modules/ws/lib/websocket-server.js:89:16)                                                                                      
backend_1     |     at Server.emit (events.js:198:13)                                                                                                                                                              
backend_1     |     at Server.EventEmitter.emit (domain.js:448:20)                                                                                                                                                 
backend_1     |     at onParserExecuteCommon (_http_server.js:553:14)                                                                                                                                              
backend_1     |     at onParserExecute (_http_server.js:499:3)                                                                                                                                                     
backend_1     | (node:17) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise whic
h was not handled with .catch(). (rejection id: 1) 

@dnalborczyk
Copy link
Collaborator

dnalborczyk commented Jul 8, 2019

@CorentinDoue we don't have (m)any tests for websocket yet. that's why it's also marked as experimental, so we could release it quicker to get feedback.

it's this line, when one doesn't have any query params:

if (Object.keys(queryStringParameters).length > 0) {

with queryStringParameters being null:

Object.keys(null).length > 0

// TypeError: Cannot convert undefined or null to object

@dherault gonna hotfix it with:

if (Object.keys(queryStringParameters || {}).length > 0) {

@CorentinDoue
Copy link
Author

Thank you :)

@dnalborczyk
Copy link
Collaborator

@dherault could you do another patch release for this fix?

@dherault
Copy link
Owner

v5.7.3!

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

No branches or pull requests

3 participants