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/#415 dynamic port binding #417

Merged
merged 6 commits into from
Mar 15, 2019
Merged

Conversation

jiachen1120
Copy link
Contributor

@jiachen1120 jiachen1120 commented Mar 2, 2019

@NicholasAzar @stevehu Hey! I am sorry that I have not fulfilled my duties to complete the task you handed in. I just did a test and found that there may still be some areas to improve on this issue.

I just did a manual test of develop branch and found the following problems:

If the user is using a static port and the port happens to be occupied, the user will get the following information:

Fail to bind to port 8453, trying 8454

And at this point the server does not stop, perhaps this will make the user mistakenly think that the server is always trying to bind the port. I think we should let the exception throw at the moment.

Then, I test @NicholasAzar changes. due to the whole bind() is put in to try catch block, the registration exception would be caught by outer try-catch and the user would get the port bind fail message when the registration fails.

In summary, I made some changes to make sure the following performance:

  1. (dynamic port) keep trying until reach valid port. If registration fails, the server stop after tried the first port.
  2. (static port) trying to bind port. If fail, throw the exception.

Related topics:
#416
#415

@codecov-io
Copy link

codecov-io commented Mar 2, 2019

Codecov Report

Merging #417 into develop will decrease coverage by 0.05%.
The diff coverage is 0%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop     #417      +/-   ##
=============================================
- Coverage      49.47%   49.42%   -0.06%     
  Complexity      1649     1649              
=============================================
  Files            240      240              
  Lines          10432    10443      +11     
  Branches        1498     1501       +3     
=============================================
  Hits            5161     5161              
- Misses          4654     4665      +11     
  Partials         617      617
Impacted Files Coverage Δ Complexity Δ
...ver/src/main/java/com/networknt/server/Server.java 27.01% <0%> (-1.09%) 14 <0> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 205d7e0...d774075. Read the comment docs.

@DSchrupert
Copy link
Member

@jiachen1120 I think minPort should be ok to equal maxPort, just when it's strictly greater should there be an error

@jiachen1120
Copy link
Contributor Author

@NicholasAzar I also think it should be ok to equal in theory, but the previous performance is that the range of the port is: minPort <= port < maxPort. If let minPort equal to maxPort, no error message appear and no port bound successfully. So in order to make the previous performance unchanged I make such kind of change. @stevehu Or, maybe should we change the port range to
minPort <= port <= maxPort?

@stevehu
Copy link
Contributor

stevehu commented Mar 15, 2019

@jiachen1120 @NicholasAzar We are discuss the edge case now. In most of the cases, users won't use dynamic port if the minPort and maxPort is equal. They would assign the port directly without dynamic port enabled. That being said, we cannot predict user behaviors. In the case that minPort is equal to maxPort, we should try to bind to it and quit with error if that particular port is not availabe. If that means we have to break the previous behavior, then let's break it as I don't think anybody is depending on the behavior. I think we should change the port range to minPort <= port <= maxPort as @jiachen1120 suggested.

@stevehu stevehu merged commit cdc29d8 into develop Mar 15, 2019
@stevehu stevehu deleted the fix/#415-dynamic-port-binding branch March 15, 2019 16:19
younggwon1 pushed a commit to younggwon1/light-4j that referenced this pull request Feb 10, 2024
* - overload getConfigStream method in config module to get config stream from classpath or default

* revert

* Service terminate with error message when minPort larger than or equal to maxPort

* Changed dynamic port interval
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.

5 participants