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

fs watcher is never closed #359

Open
matthieusieben opened this issue Apr 10, 2018 · 7 comments
Open

fs watcher is never closed #359

matthieusieben opened this issue Apr 10, 2018 · 7 comments
Labels
project tracked in a project

Comments

@matthieusieben
Copy link

When the autoReload option is set, an fs.FSWatcher is created by the call to fs.watch(...).

This watcher prevents the process to exit properly.

Moreover, if the configure option is called more than once, several watchers are created, causing a memory leak.

This watcher should:

  1. Be closed when the process beforeExit event is emitted.
  2. Be closed whenever a ne configuration is called.
@vincentwinkel
Copy link

vincentwinkel commented Apr 1, 2020

I experience the same issue.
Production server, option autoReload enabled, we provide a backend which lets people change translations. While saving, we write in the i18n files, and the server totally crashes... we need to restart it.

To me, this issue should fixed asap.

@mashpie
Copy link
Owner

mashpie commented Apr 1, 2020

While I get your use case, you should not run production server with autoLoad enabled. Instead use public method i18n.addLocale(locale) (https://github.com/mashpie/i18n-node/blob/master/i18n.js#L519) to programmatically re-read your locales from storage.

Still any PR to fix fs.watch is much appreciated as this might also affect any dev env (for which autoLoad initially was intended)

@vincentwinkel
Copy link

Thanks, I'm trying.
Here is my config:

i18n.configure({
	locales: ['some','locales'],
	directory: '/some/path',
	defaultLocale: 'someLocale',
	cookie: null,
	autoReload: false,
	updateFiles: false,
	register: {}
});

So autoReload = false. Now I update a i18n file from my backend:

fs.writeFile('/local/file.json', JSON.stringify(translations), () => {
	res.redirect('/some/url')
})

And I directly see the change applied on the frontend...
I should explicitly reload the locale to see the change, no?

@mashpie
Copy link
Owner

mashpie commented Apr 2, 2020

right.

fs.writeFile('/locals/en.json', JSON.stringify(translations), () => {
  i18n.addLocale('en')
  // res.redirect('/some/url') ## whatever it takes in your use case
})

more details in #168 and #169

@vincentwinkel
Copy link

What I mean is that only by writing the i18n file, it's automatically reloaded, even with autoReload = false. So 2 cases:

  1. autoReload is useless or I don't understand it
  2. there is a bug

@mashpie
Copy link
Owner

mashpie commented Aug 15, 2020

@vincentwinkel i18n is reading files

  1. by invoking i18n.configure()
  2. by fs.watch with autoReload enabled
  3. by invoking i18n.addLocale()
  4. implicitly when calling any translation method (__(), _n(), etc.) on any missing locale

but either way - this issue is about properly closing fs.watch as @matthieusieben described earlier

@mashpie mashpie added the project tracked in a project label Aug 19, 2020
@janwo
Copy link

janwo commented Nov 7, 2020

Any updates ? :)

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

No branches or pull requests

4 participants