lndk-org / lndk

MIT License
76 stars 19 forks source link

Init logger in a thread-safe manner #86

Closed orbitalturtle closed 6 months ago

orbitalturtle commented 7 months ago

This fixes a problem we were having in the integration tests. When we would run the lndk binary in each test -- the second time the logger was initialized it would throw an error.

With this fix, when the logger is called a second time, it operates normally. Fixes #83.

carlaKC commented 6 months ago

Doesn't this mean that we won't have logs in the second itest if this race occurs?

Happy to put it in temporarily, but waiting for proper shutdown seems like a more sustainable path?

orbitalturtle commented 6 months ago

@carlaKC No, it'll still successfully run the logger, it just blocks until "init" no longer returns an error -- so it effectively waits for the last logger to shut down before it runs init. So it does what you're talking about but at the beginning of the program rather than the end.

I spent quite a while trying to find something more along the lines of what you're talking about -- but couldn't find anything unfortunately. If you find something you like better that's fine with me though. The current approach was recommended to me in this post: https://users.rust-lang.org/t/shutting-log4rs-down-cleanly/104239/4

orbitalturtle commented 6 months ago

@carlaKC Hey would it be cool if we merge this? Having this in would make the send offers chain-of-PRs a bit easier to manage and it gets us logs in more than just the first integration test :)