ebarlas / microhttp

Fast, scalable, self-contained, single-threaded Java web server
MIT License
539 stars 54 forks source link

Make sure that the ports are released when the EventLoop stops #21

Closed filiphr closed 1 year ago

filiphr commented 1 year ago

I am not that familiar with the java nio channels. However, while trying to use the EventLoop for some testing I realised that stopping the event loop is still holding the port.

By testing I mean to use Microhttp in our test suite as a mock web server

filiphr commented 1 year ago

As mentioned in PR #20, I added some cleanup for the ConnectionEventLoop as well. However, my knowledge in the area of NIO is very limited and I am not sure if what I am doing there is right and whether it makes sense. So feel free to change anything or direct me in an approach to make this work properly.

A side question. Does it make sense to think about making the EventLoop implement AutoCloseable? I think that Java went in that direction with the ExecutorService

ebarlas commented 1 year ago

Thanks for addressing this gap! I don't think I've tried start-stop cycles in the same application.

filiphr commented 1 year ago

Thanks for addressing this gap! I don't think I've tried start-stop cycles in the same application.

Thanks for accepting the PRs and integrating them so fast. Just as an FYI, I found this by accident, since the default for the EventLoop was 8080. In our tests we are using 0 for the port. However, that still got me thinking that if we have a lot of tests where we spin up a new EventLoop then ports keep staying open, and I figured that shouldn't be good. I know that once all tests are done and the JVM exits the ports will be released, but still wanted to tackle the issue

ebarlas commented 1 year ago

You're welcome!

I just released version 0.10 with these changes.

filiphr commented 1 year ago

I just released version 0.10 with these changes.

That's awesome, thank you very much. I am leaving on vacation today, but when I am back I will definitely pick it up and continue playing with MIcrohttp.