SetLang is not thread safe and memory leak

109 views
Skip to first unread message

myl...@gmail.com

unread,
May 13, 2020, 11:59:08 AM5/13/20
to golang-nuts
I have just used golang for a month and I am not very familiar with this on.

SetLang is not thread safe and memory leak?

https://github.com/mylukin/easy-i18n/blob/master/i18n/i18n.go#L43

Please expert guidance, and how to fix it?

Message has been deleted
Message has been deleted

Axel Wagner

unread,
May 13, 2020, 4:14:19 PM5/13/20
to myl...@gmail.com, golang-nuts
I'm afraid I don't understand the question. I guess you are referring to this PR?
It seems wrong in multiple ways (for starters, they change the module path), but it also seems outdated; you have put several commits on master since then.
From a casual glance at your code there is at least one race-condition: While SetLang is protected by a mutex, none of the other methods of Printer are. So calling SetLang concurrently with any other method will create a data-race.
Apart from that the PR changes the API quite a bit and the "memory leak" they talk about seems to be something they introduce themselves in the first commit by using a global map and not provide a way to remove an element from it - and then they fix that in the second commit by adding a new function.

Overall, I'm afraid to provide help, there needs to be a clear question though. If you are indeed wondering about the PR, I think the best way to address that would be to ask the author; it's their change and it's fine to ask for clarification of what they are trying to achieve before accepting it.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3f7cafe7-1ca3-499f-8819-905fd2e9eaa3%40googlegroups.com.

Lukin

unread,
May 14, 2020, 1:17:43 AM5/14/20
to Axel Wagner, golang-nuts
Thanks. 

Axel Wagner <axel.wa...@googlemail.com> 于 2020年5月14日周四 04:13写道:
Reply all
Reply to author
Forward
0 new messages