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

Transmit doesn't work with PM2 cluster #19

Closed
sivo1981 opened this issue Apr 29, 2024 · 7 comments
Closed

Transmit doesn't work with PM2 cluster #19

sivo1981 opened this issue Apr 29, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@sivo1981
Copy link

sivo1981 commented Apr 29, 2024

Package version

@adonisjs/transmit@1.0.0

Describe the bug

When application is deployed to PM2 cluster, subscribe request fails randomly on some nodes, because this line returns false.

return this.#storage.addChannelToStream(uid, channel)

I have configured Redis with ioredis and this works fine for subscribeToChannel, but the problem is that createStream doesn't publish UID to all other nodes with this.#bus?.publish and StreamChannelRepository has an empty set.

const channels = this.#channelByUid.get(uid)

Reproduction repo

No response

@RomainLanz
Copy link
Member

Hey @sivo1981! 👋🏻

problem is that createStream doesn't publish UID to all other nodes

This is the expected behavior. Your registration stays within one Node (where the stream was open).

Could you give me more information on what does not work? The best would be to create a small reproduction or a failing test.

@RomainLanz RomainLanz self-assigned this Apr 30, 2024
@sivo1981
Copy link
Author

Application is started on PM2 with 2 instances.

Transmit config:

export default defineConfig({
  pingInterval: '1m',
  transport: {
    driver: redis({
      host: env.get('REDIS_HOST'),
      port: env.get('REDIS_PORT'),
      password: env.get('REDIS_PASSWORD')
    })
  }
})

PM2 logs:

NODE-1 | Transmit connected: 55f07e6f-0562-4b93-949f-ff2bf139ab3d"}
NODE-1 | Transmit subscribed 55f07e6f-0562-4b93-949f-ff2bf139ab3d to users
NODE-1 | POST - /__transmit/subscribe - 204 - 19 ms
NODE-0 | Transmit subscribed 55f07e6f-0562-4b93-949f-ff2bf139ab3d to users/21
NODE-0 | POST - /__transmit/subscribe - 400 - 9.35 ms

Initial transmit connect was made on node 1 and first subscribe is successful beacuse it was requeste on the same node as connect. The problem is in second subscribe request which goes on node 0 and response with HTTP 400 code. This happens because this.#storage.addChannelToStream(uid, channel) returns false.

Hope this helps you investigate this problem.

@sivo1981
Copy link
Author

Any news regarding this issue?

@RomainLanz
Copy link
Member

Yes, sorry for the late reply.
The status code sent back is wrong and will be fixed shortly, but the subscription should still be broadcasted and registered despite the response sent by the backend.

Have you tried it or stopped when getting this 400?

@sivo1981
Copy link
Author

I can confirm that despite getting HTTP 400 error code, subscription is successful on the server and events are received on the client normally.

@RomainLanz RomainLanz added the bug Something isn't working label May 15, 2024
@RomainLanz
Copy link
Member

Perfect thanks!

@RomainLanz
Copy link
Member

Released in 1.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants