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 Handler Creation Timing #766

Closed
nalanj opened this issue Aug 1, 2019 · 5 comments
Closed

Websocket Handler Creation Timing #766

nalanj opened this issue Aug 1, 2019 · 5 comments
Labels

Comments

@nalanj
Copy link

nalanj commented Aug 1, 2019

From usage and reading the code, it seems that websocket handlers are created on startup instead of on first usage, but handlers for http endpoints seem to be created on usage. That took me into a weird edge case with persisting db connections, so I wanted to check in on if that's the expected, desired behavior or if it's something you'd like to see change in the future.

@dnalborczyk
Copy link
Collaborator

hey @nalanj

thanks for reporting the issue! websocket support is fairly new, and that's a short coming which we should fix in the near future.

That being said, it shouldn't cause any issues. Out of curiosity, what's the edge case you are experiencing?

@nalanj
Copy link
Author

nalanj commented Aug 1, 2019

I'm persisting database connections and that was leading to issues within http handlers because they were creating a new handler on each request and eventually requests would run out of connections. I put some offline only logic in to clean those up, but at that point I saw the opposite issue with socket handlers because the connection would get cleaned up before the socket handler was done running.

On reading through the code it looks like a handler should get created each time a socket message comes in rather than up front - does that seem correct?

@dnalborczyk
Copy link
Collaborator

dnalborczyk commented Aug 1, 2019

within http handlers because they were creating a new handler on each request

handlers should be created only once, on usage. what you might be experiencing is that when you edit the code it will reload the handler, which I think is the cause for a lot of problems. I think in the next major version we should remove the auto-reload, and make that an option, instead of the default.

could you try setting skipCacheInvalidation (either cli or custom options) and see if this fixes your issue? be aware that the auto-reload for handlers is then turned off, and you have to either restart the plugin on your own, or better, use something like nodemon

On reading through the code it looks like a handler should get created each time a socket message comes in rather than up front - does that seem correct?

yes and no. handlers should get loaded and created when they are being called, like AWS does, but they should stay "loaded", at least for a certain amount of time, like AWS does as well.

@dnalborczyk
Copy link
Collaborator

@nalanj handler loading and execution has been re-written and changed substantially. could you give the latest v6 alpha a try to see if it fixes your issue?

just for reference, this might be related: #798

@dnalborczyk
Copy link
Collaborator

I'm persisting database connections and that was leading to issues within http handlers because they were creating a new handler on each request and eventually requests would run out of connections.

@nalanj I just tried to reproduce #798 and found out that the require cache invalidation on each equest causes this to happen. you can read more here: #798 (comment)

could you let me know if --skipCacheInvalidation fixes this for you (in v5)? or better also try v6 alpha which has been entirely re-written and behaves now closer to AWS Lambda.

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

2 participants