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

fix: Port already bound Error #56

Closed
wants to merge 13 commits into from
Closed

Conversation

varshith257
Copy link

@varshith257 varshith257 commented Jul 1, 2024

@varshith257
Copy link
Author

varshith257 commented Jul 1, 2024

@jdegoes I have a similar experience working on a port already bound issue with the Kubernetes organization. I have implemented the retry mechanism to allocate port as same as what I have done in Kubernetes to ensure port bound error doesn't exist anymore :)

It's ready for your review

@varshith257
Copy link
Author

@jdegoes Have a look at this PR

@varshith257
Copy link
Author

@jdegoes Could you take a time to review this PR?

@varshith257
Copy link
Author

@jdegoes A gentle reminder to have a look on it 😄

@varshith257
Copy link
Author

@jdegoes PTAL

build.sbt Outdated Show resolved Hide resolved
Copy link
Member

@khajavi khajavi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR doesn't resolve the issue mentioned! Please open the PR whenever it is resolved!

sbt:zio-quickstart-restful-webservice> run
[info] running dev.zio.quickstart.MainApp
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
timestamp=2024-08-16T15:43:51.288677Z level=ERROR thread=#zio-fiber-1 message="" cause="Exception in thread "zio-fiber-10,6,4" io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
        at dev.zio.quickstart.MainApp.run(MainApp.scala:16)"
[error] Exception in thread "zio-fiber-10,6,4" io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
[error]         at dev.zio.quickstart.MainApp.run(MainApp.scala:16)
[error]         at dev.zio.quickstart.MainApp.run(MainApp.scala:16)
[error] Caused by: io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
[error] stack trace is suppressed; run last Compile / run for the full output
[error] (Compile / run) Exception in thread "zio-fiber-10,6,4" io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
[error]         at dev.zio.quickstart.MainApp.run(MainApp.scala:16)
[error] Total time: 3 s, completed Aug 16, 2024, 7:13:51 PM
sbt:zio-quickstart-restful-webservice> run
[info] running dev.zio.quickstart.MainApp
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
timestamp=2024-08-16T15:44:09.636552Z level=ERROR thread=#zio-fiber-1 message="" cause="Exception in thread "zio-fiber-10,6,4" io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
        at dev.zio.quickstart.MainApp.run(MainApp.scala:16)"
[error] Exception in thread "zio-fiber-10,6,4" io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
[error]         at dev.zio.quickstart.MainApp.run(MainApp.scala:16)
[error]         at dev.zio.quickstart.MainApp.run(MainApp.scala:16)
[error] Caused by: io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
[error] stack trace is suppressed; run last Compile / run for the full output
[error] (Compile / run) Exception in thread "zio-fiber-10,6,4" io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
[error]         at dev.zio.quickstart.MainApp.run(MainApp.scala:16)
[error] Total time: 3 s, completed Aug 16, 2024, 7:14:09 PM
sbt:zio-quickstart-restful-webservice>

@khajavi khajavi closed this Aug 16, 2024
@varshith257
Copy link
Author

@khajavi Have you tried with updated cmds in README.md?

sbt-resolver plugin is used for this

@khajavi
Copy link
Member

khajavi commented Aug 16, 2024

@varshith257
It is preferable not to change the commands, as we need to update all the tutorials on zio.dev referenced to this quickstart.

@varshith257
Copy link
Author

It is the library suggested by @guizmaii which works good for this Port bind error. Or else my previous approach of retry logic

@khajavi
Copy link
Member

khajavi commented Aug 16, 2024

@varshith257
We need consistent material across zio.dev and zio-quickstarts. Please see this page: https://zio.dev/guides/quickstarts/restful-webservice
The sbt-respolver is a good plugin but If you propose using it, I suggest creating PR to update documentation.

@varshith257
Copy link
Author

varshith257 commented Aug 16, 2024

Ok, I will add docs for it in a note for Zio-quickstarts in Zio.dev for this problem. I also mention how to configure this plugin instead the updation of here

@khajavi
Copy link
Member

khajavi commented Aug 16, 2024

@varshith257
To reduce the number of changes and make it consistent with other quick starts, I suggest resolving this issue without switching to alternative commands other than the sbt run.

@varshith257
Copy link
Author

varshith257 commented Aug 16, 2024

What about port retry logic?

#56 (comment)

@khajavi
Copy link
Member

khajavi commented Aug 17, 2024

How does that logic resolve this issue? Will it handle the ctrl+c signal and release the acquired port?

@varshith257
Copy link
Author

Yes, it will check for that porr if is already occupied it checks for another free port. So that there is no choice that Port bind error occurs

@khajavi
Copy link
Member

khajavi commented Aug 17, 2024

The reason the user can't bind to that port is that on the last run, the port was not successfully released. So, you need to release it instead of choosing another port.

@varshith257
Copy link
Author

varshith257 commented Aug 18, 2024

@khajavi Here we go! Check out this PR, the solution releases port and no changes to any cmds

@guizmaii
Copy link
Member

guizmaii commented Aug 18, 2024

@khajavi, I disagree with you here. We need to improve the current examples by introducing sbt-revolver.

as we need to update all the tutorials on zio.dev referenced to this quickstart.

Well, that means that updating the doc for part of this work.

But we should not introduce dedicated code to do this release like done here #57
This isn't a good example to give. That's not how things should be done.

This PR doesn't resolve the issue mentioned!

Yes, it does solve the issue because sbt-revolver solves the issue by introducing the reStop command which stops the server.
It also introduce hot-reloading, which is essential to any good zio-http project, that's why I think we need to improve these example by adding this sbt plugin. It'll give better quickstart projects to people. Closer to what we actually do.

Finally, sbt-revolver is part of the zio-http doc and should be used instead of sbt run for an zio-http project.
See https://zio.dev/zio-http/installation#hot-reload-changes-watch-mode

@varshith257
Copy link
Author

I am in the situation of two reviewers different perspectives 😅

Both have valid reasons. Yes, but if example semantics doesn't need to change as well as the newbie who starts zio with quickstarts can feel it overwhelmed with what's happening with this diff lines of codes rather than being intended with perspective of showing him about Zio concepts. For this i agree with @guizmaii

To reduce the number of changes and make it consistent with other quick starts, I suggest resolving this issue without switching to alternative commands other than the sbt run.

For this i agree with @khajavi

@varshith257
Copy link
Author

How about adding sbt-revolver plugin to quickstarts and add the single line in docs of quickstarts under a note to redirect here for port binding errors
https://zio.dev/zio-http/installation/#hot-reload-changes-watch-mode

@khajavi
Copy link
Member

khajavi commented Aug 18, 2024

@guizmaii Overall, I understand and acknowledge your comments. Let me elaborate:

@khajavi, I disagree with you here. We need to improve the current examples by introducing sbt-revolver.

as we need to update all the tutorials on zio.dev referenced to this quickstart.

Well, that means that updating the doc for part of this work.

That was the concern about maintaining uniform material across documents and quickstart source codes, but not enforcing how to do that. As I mentioned, I'm not opposed to the sbt-resolver approach.

But we should not introduce dedicated code to do this release like done here #57

Makes sense and I agree

Yes, it does solve the issue because sbt-revolver solves the issue by introducing the reStop command which stops the server.

I mentioned that it's not fixed because the reported issue is expected when using sbt run. To resolve this issue, forking the JVM on the run command as a simple solution or adding sbt-resolver requires updating the corresponding quickstarts and tutorials on zio.dev as part of this effort; both are acceptable IMHO.

@varshith257
Copy link
Author

@guizmaii What do you think ? Lets go with sbt-revolver plugin ?

@guizmaii
Copy link
Member

@varshith257 Yes and part of your work here is to update the documentation too

@guizmaii
Copy link
Member

@khajavi Thanks for your detailed answer :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants