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

language: Prevent data race while registering plural specs #81

Closed
wants to merge 1 commit into from

Conversation

n10v
Copy link
Contributor

@n10v n10v commented Oct 30, 2017

@nicksnyder
Copy link
Owner

Why do you think that go-i18n should be responsible for protecting against this data race instead of the consumer of the library?

@n10v
Copy link
Contributor Author

n10v commented Oct 31, 2017

Why not?

@nicksnyder
Copy link
Owner

nicksnyder commented Oct 31, 2017

For the same reasons that map itself isn’t goroutine safe.

  1. Everyone shouldn’t pay the cost of synchronization if they don’t need it.
  2. You frequently need synchronization at a higher level anyway so doing synchronization at lower levels is unnecessary complexity and a waste of CPU.

Your Go program should load translations during its initialization.

More specifically, go-i18 was never designed to be goroutine safe (for the above reasons) and I would be surprised if this were the only change needed to make it completely goroutine safe. Making it partially goroutine safe is not intuitive.

I don’t know how Hugo is architected, but it isn’t clear to me that this change would solve your problem anyway. This change may solve the low level data race but it would not necessarily prevent you from reading from the translation store before all the data is writen (which is really what you should be enforcing) and go-i18 can’t really help you with that. This is what I meant by “synchronization at a higher level”.

go-i18n is just a nice wrapper around maps specifically for i18n. If you need synchronization then I think that belongs at the app layer.

@n10v
Copy link
Contributor Author

n10v commented Oct 31, 2017

Ok. You're right. I close it.

@n10v n10v closed this Oct 31, 2017
@bep bep mentioned this pull request Nov 2, 2017
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

Successfully merging this pull request may close these issues.

2 participants