Serverless-offline: Websocket support broken

Created on 8 Jul 2019  路  7Comments  路  Source: dherault/serverless-offline

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



md5-ca851975519cabe40d91e606f8eaf010



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)



md5-2232e2582494b008c2987f4b518f1c9a



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

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

Thank you :)

bug

All 7 comments

Will be fixed in minutes!

v5.7.2

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) 

@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) {

Thank you :)

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

v5.7.3!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FranzSkuffka picture FranzSkuffka  路  3Comments

stunningpixels picture stunningpixels  路  3Comments

Ali-Dalal picture Ali-Dalal  路  4Comments

stonebraker picture stonebraker  路  3Comments

aldofunes picture aldofunes  路  3Comments