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

Introduce IdPool interface #52

Closed
wants to merge 5 commits into from
Closed

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Sep 15, 2020

After debugging Skipper's goroutine leak, @adri came with the idea to completely disable the dynamic id pool for Skipper.

I think it makes sense, as Skipper doesn't need this pool because it creates and destroys clients for every request.

Therefore, this PR introduces an IdPool interface with 2 implementations: DynamicIdPool (current implementation) and a new StaticIdPool that always allocates the same number.

This could be used by projects that don't need to have an always running goroutine that generates ids (Skipper for example).

Todo

@yookoala WDYT about this? Would this make sense?

@yookoala
Copy link
Owner

I'm not entirely convinced that this caused issue #48. But this is a nice addition to the current code base. Please rebase on the current master branch. I will merge after this.

@ruudk ruudk force-pushed the id-pool-interface branch 2 times, most recently from d9030db to eab1288 Compare September 29, 2020 09:13
@ruudk
Copy link
Contributor Author

ruudk commented Sep 29, 2020

@yookoala I improved the PR a bit. Is this the right direction? I'm getting stuck with the tests, and fail to fix it properly. Could you advice me? 🙏

@yookoala
Copy link
Owner

yookoala commented Sep 30, 2020

@ruudk: The newly written dynamic id pool has some data race issue. I believe the go routine line 58 in id_pool.go needs some work to detect the ids channel's closing and simply quit. Alloc and Release should now detect the channel's closing and work differently (you cannot send to or read from closed channel or nil).

Check these links out to see if you get any inspiration:

And introduce 2 implementations: DynamicIdPool (current implementation) and a new StaticIdPool that always allocates the same number.

This could be used by projects that don't need to have an always running goroutine that generates ids (Skipper for example).
This will be a breaking change because it will prevent calling `ServeHTTP` multiple times on a `gofast.NewHandler`. This is something that is happening inside `example/php/php_test.go:TestNewSimpleHandler`.  I'm not sure if that is even a good thing to do.
I think that Client.Close() should close the IdPool too. Because `ServeHTTP` in  `gofast.NewHandler` will always defer `Client.Close()` I think it means that `ServeHTTP` can not be called multiple times.

Therefore I decided to rewrite the tests to make it pass.
@ruudk
Copy link
Contributor Author

ruudk commented Jan 20, 2021

@yookoala Today I decided to give this another shot and I was able to fix the race condition on Go 1.15. Turns out that it doesn't work on Go 1.11 but I believe that's because the race condition checker has been improved since then? (turns out it fails randomly 🤯 , any idea?)

I added multiple commits because this is not 100% ready to merge yet. I would first want to get your opinion on how to solve this properly.

In 97b6027 I added a sync.WaitGroup to manage the shutdown of the pool. This works fine, except for 1 test.

I thought this might be a breaking change, so I removed it, to get the tests passing again in 4a2618a

But I feel it should be done like this: f674ebf

What do you think?

@ruudk
Copy link
Contributor Author

ruudk commented Jan 21, 2021

I verified that this PR fixes the Skipper goroutine leak 🎉

@yookoala
Copy link
Owner

When rerun the test, the racing is gone. This is probably due to some minor difference in the parallel steps in initialization. I'll check on this more.

@ruudk
Copy link
Contributor Author

ruudk commented Jan 31, 2021

Any update? 🙏

@yookoala
Copy link
Owner

yookoala commented Feb 2, 2021

Still testing if I can get rid of the occasional race condition. Please wait.

@yookoala
Copy link
Owner

@ruudk: #70 has introduced a simpler idPool implementation without creating an extra interface. I think this might be a simpler solution to the memory leak issue. Please go ahead and check if it really solve the issue. We can revisit this interface idea if needed.

@ruudk ruudk closed this Feb 19, 2021
@ruudk ruudk deleted the id-pool-interface branch February 19, 2021 19:39
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.

None yet

2 participants