-
Notifications
You must be signed in to change notification settings - Fork 55
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
Ably Not Subscribing to Events in Production #1582
Comments
➤ Automation for Jira commented: The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-4041 |
Hey @coreyarch4321. I saw your note on Twitter so having a quick look before our team gets back to you. One thing that I think would be useful for us is for you to have a think what is different between your local and production environments. Ably does not differentiate production/dev/local development in any way whatsoever. Some customers use separate apps for production and dev, but on our end they're just apps, and we treat all traffic and client connections the same. So whilst we will certainly try and help resolve this for you, knowing more about what's different between these environments may help to more quickly resolve this issue. Can you have a think about what may be different between the two that is relevant? |
Hi @mattheworiordan . Thanks for looking into this. Here are some differences that may be worth mentioning:
I can't really think of anything else worth mentioning. Please let me know if you have any other questions. |
Hi @coreyarch4321, Here are the outcomes of the internal investigation into the issue:
The issue arises from the fact that Ably Realtime's connections are persistent and maintain state over time, while serverless functions are designed to be stateless and short-lived. If you have any further questions or require additional clarification, feel free to ask. I will leave this issue open and suggest that we work on improving the documentation to provide more specific guidance on using Ably in serverless environments. |
@coreyarch4321 it's also worth mentioning that you can utilize Ably's Webhook functionality in serverless environments. |
Thank you all. The fix works. For anyone else running into the problem, here is a TLDR of the issue and the solution I'm using: The issue was that Vercel has a default execution timeout for their backend functions (serverless functions). That means that within 10 seconds or so, the ably connection would die out. This is why the backend subscriptions were not triggering. My solution is to send a regular HTTP request to the backend instead of publishing. Then, on the backend, instead of publishing via ably realtime, I'll simply use the REST API (which does not require a persistent connection to Ably). This has worked fine for me. Hopefully this helps someone else. The important takeaway is - if your backend subscriptions aren't working in a Vercel production environment, this is probably the issue^. |
I shipped an application to production using Vercel and Ably. In short, on a button click, I publish an event to a channel from my react client. On my node backend, I am subscribed to that channel for that specific event. In my local setup, the event listener triggers perfectly, but in production, the event never runs. I've used the Ably dev console to publish the same event on that channel and that still doesn't work.
I've used
log: { level: 4 }
to output verbose logs using Axiom and it seems that ably connects to the proper channel on the backend.Here is the problem in more detail, with files attached for the logs, ably dev console and code snippets.
FRONT END:
Note: The expected outcome is that ably will respond to the "match_not_found" event that is published on the "match-finding-user-1" channel from the backend. You can see that in "FindingMatchDialog.js", if ably were to respond to the "match_not_found" event, we would get a console.log of "listening to Match not found". The issue is that this never gets logged.
BACK END:
On the backend, we define the "/token-request" API route that returns the ably instance for the frontend to use (see "routes/ably/index.js" code snippet).
We have an "ably-service" file that runs an "initialize" function. This connects to ably.
The initialize function also runs the function, "setUpAllUsersChannelSubscriptions". This function connects to the "all_users_matching_channel" channel (recall from the frontend). We set up the subscription on that channel for the event, "match_request". In that subscription handler, we run the function, "mockOnMatchRequest" function.
It is this "match_not_found" event that should then be listened to on the front end. So here is the issue:
THE ISSUE:
The "match_not_found" is never listened to on the frontend. It seems like the "mockOnMatchRequest" on the backend is not run at all. None of the logs are outputted.
It turns out that after the button press, no new backend logs appear. It's as if the "match_request" event is not being listened to on the backend. I've attached screenshots of the Ably dev console, where I've attached to the "all_users_matching_channel" and the "match-finding-user-1" channel. You'll notice that the "match_request" event does get published (as seen in the Ably dev console). However, the "match_not_found" never shows up on the Ably dev console. This makes me believe there is something wrong with the subscription to the "all_users_matching_channel" for the event, "match_request".
You have a copy of the JS code where I subscribe to the "all_users_matching_channel" on the backend, so please let me know if something is being done incorrectly there.
MY HUNCHES:
I hope this abundance of information is not overwhelming. Please take a look at how I am connection to ably, publishing/subscribing to the events (especially on the backend). Hopefully, you can help me figure out what the issue is. Also, this is all working fine on my local environment, so that makes it a little tougher.
Thank you! And let me know if you need any more information or clarification.
Here are the code snippets:
FindingMatchDialog.js
**
useChannel.js
**
ably-service/index.js
**
routes/ably/index.js
**
FindingMatchDialog.js.pdf
![all_users_matching_channel](https://private-user-images.githubusercontent.com/61270222/297968658-a425b8e1-3ac1-43d2-a843-cdf326e26afa.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE3NjEzNTQsIm5iZiI6MTcyMTc2MTA1NCwicGF0aCI6Ii82MTI3MDIyMi8yOTc5Njg2NTgtYTQyNWI4ZTEtM2FjMS00M2QyLWE4NDMtY2RmMzI2ZTI2YWZhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzIzVDE4NTczNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU4Zjc1MDNkOTZlMDZhZGY1OTM2ZDQyYjUwZTc0N2E4OTA4NmYwYmJmZTIyNjM2YmIwOGE2MDRjNDYyMzg2YjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.210GGTvnauu90lYc8ACEQqpcafN94gSP4DTK_yHZdoo)
![match-finding-user-1](https://private-user-images.githubusercontent.com/61270222/297968660-ce4a090d-90e5-4843-8459-52eff955b9ad.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE3NjEzNTQsIm5iZiI6MTcyMTc2MTA1NCwicGF0aCI6Ii82MTI3MDIyMi8yOTc5Njg2NjAtY2U0YTA5MGQtOTBlNS00ODQzLTg0NTktNTJlZmY5NTViOWFkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzIzVDE4NTczNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgxYjA5YTBmNmFjMzMzNWYzZDhiMzJmNzIwOWE3MTFkOGY5NDdkNDg2ZjgwNTYxNjkxYjFhOWZjZGIyMjI0NWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.AqOJcSZhthrw0x9cDcRRE3hglEnNjyDtWutfSjd1PWc)
useChannel.js.pdf
ably-service-index.js.pdf
routes-ably-index.js.pdf
backend-end-logs.pdf
front-end-logs.pdf
ably-dev-console.pdf
The text was updated successfully, but these errors were encountered: