feathersjs-ecosystem / feathers-sync

Synchronize service events between Feathers application instances
MIT License
222 stars 41 forks source link

Can't get it to work #80

Closed dottodot closed 6 years ago

dottodot commented 6 years ago

On a single server I can see it populating events in my mongodb but as soon as I scale to 3 servers it stops working and I get socket connection errors such as

WebSocket connection to 'wss://api.example.com/socket.io/?EIO=3&transport=websocket&sid=yXLuMAYr79h-YcadAAAA' failed: Error during WebSocket handshake: Unexpected response code: 400
 Authentication timed out
daffl commented 6 years ago

What does it show when running the application with the DEBUG=feathers-sync environment variable?

dottodot commented 6 years ago

On the first hit to the site I got

2018-05-01T07:50:36.793847Z app[web.cluster2-27b0a9a1-59e1-4c2f-ab4c-a29009b041b7]: 2018-05-01T07:50:36.793Z feathers-sync Sending sync-out event 'authentication created'
2018-05-01T07:50:36.804535Z app[web.cluster1-7e7974e4-2e7b-4f4a-bdf9-dbde4f42e2c8]: 2018-05-01T07:50:36.804Z feathers-sync Dispatching sync-in event 'authentication created'
2018-05-01T07:50:36.806649Z app[web.cluster3-93d16b00-09cd-42b7-b2dd-ef0ddd361c20]: 2018-05-01T07:50:36.806Z feathers-sync Dispatching sync-in event 'authentication created'
2018-05-01T07:50:36.805525Z app[web.cluster2-27b0a9a1-59e1-4c2f-ab4c-a29009b041b7]: 2018-05-01T07:50:36.805Z feathers-sync Dispatching sync-in event 'authentication created'

then on a refresh I got

2018-05-01T07:51:06.769989Z app[web.cluster2-27b0a9a1-59e1-4c2f-ab4c-a29009b041b7]: 2018-05-01T07:51:06.769Z feathers-sync Sending sync-out event 'authentication removed'
2018-05-01T07:51:06.775527Z app[web.cluster3-93d16b00-09cd-42b7-b2dd-ef0ddd361c20]: 2018-05-01T07:51:06.775Z feathers-sync Dispatching sync-in event 'authentication removed'
2018-05-01T07:51:06.773676Z app[web.cluster1-7e7974e4-2e7b-4f4a-bdf9-dbde4f42e2c8]: 2018-05-01T07:51:06.773Z feathers-sync Dispatching sync-in event 'authentication removed'
2018-05-01T07:51:06.774329Z app[web.cluster2-27b0a9a1-59e1-4c2f-ab4c-a29009b041b7]: 2018-05-01T07:51:06.774Z feathers-sync Dispatching sync-in event 'authentication removed'
dottodot commented 6 years ago

Managed to resolve the issue by using io({transports: ['websocket'], upgrade: false});

Basically the same as the issue reported here https://github.com/feathersjs-ecosystem/feathers-sync/issues/55

daffl commented 6 years ago

Ooooh.... I bet it's because the default polling goes through the load balancer and the connection ends up on the wrong server. Should definitely be mentioned as a caveat then. I'm wondering if it also should be set to websockets only in the generated application. There are many issue with the none-websocket fallbacks and all supported browsers and React Native support websockets without problems.

dottodot commented 6 years ago

I now have another issue on the same setup. When trying to connect to my feathers app from another express app using socketio-client it just times out. If I scale my feathers app back to a single server it's fine.

nsainaney commented 5 years ago

For newer feathers, on the server:

app.configure(socketio({
    transports: ['websocket']
  }));