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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document global var / setting idle_timeout solutions for long-running development processes eg. Next.js #119

Closed
karlhorky opened this issue Oct 23, 2020 · 5 comments

Comments

@karlhorky
Copy link
Contributor

karlhorky commented Oct 23, 2020

Hi @porsager! 馃憢

Since a while now, students at @upleveled have been running into an issue where refreshes of a page (and Fast Refresh) are causing further database connections, and the old connections are not going away. This leads to confusing errors like (also mentioned in #42):

Error: remaining connection slots are reserved for non-replication superuser connections

The teardown / cleanup section in the readme with the prexit example appears to be helpful, but process.exit is not actually called during the development workflow (multiple page refreshes and Fast Refresh hot reloads when a file is changed).

As far as I can tell, there are a couple of different solutions to this:

  1. Set a global variable that will persist across page reloads and Fast Refresh (like this: Dev mode hot reload loses database connection聽vercel/next.js#7811 (comment))
  2. Set an idle_timeout that will cause the idle connections to be terminated fairly quickly (eg. after 2 seconds)

Would you be open to me creating a section in the readme addressing this problem with option 1 as a recommended solution for development workflows for these long-running apps? With maybe option 2 as an "alternative" solution?

karlhorky added a commit to upleveled/next-js-example-sep-2020 that referenced this issue Oct 23, 2020
@porsager
Copy link
Owner

porsager commented Oct 23, 2020

Hi @karlhorky .. Is this with v1 or v2-beta?

Hehe, scratch that, not relevant, I should read closer :) brb...

@porsager
Copy link
Owner

Ah ok, I see the issue now. I think this is probably an issue for a lot of libraries using next.js. I'm afraid it might be more confusing if information about the global workaround is added to the Postgres.js documentation - what do you think?

@karlhorky
Copy link
Contributor Author

Yes, on further consideration, I think documenting Option 1 would be misplaced in the docs here. I have asked if they would accept a PR for me to document it in the Next.js docs instead.

However, for Option 2, I would see value in having a short readme section on the fact Postgres.js does not automatically close connections, including example usage of the idle_timeout option (eg. the conversation from #42) - does that sound reasonable?

@porsager
Copy link
Owner

Yeah, that would be great! Much welcomed 馃檪

@karlhorky
Copy link
Contributor Author

Ah, thanks for f90eb2c, never ended up circling back around to this one 馃槰

Quick PR to add an example too: #171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants