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

added automatic portChange feature if current port is busy #1066

Merged
merged 11 commits into from
Nov 10, 2023

Conversation

EraKin575
Copy link
Contributor

Related Issue

  • Info about Issue or bug

Closes: #1051

Describe the changes you've made

added a automatic port changing feature for test and record mode if current port is busy
image

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Please let us know if any test cases are added

Please describe the tests(if any). Provide instructions how its affecting the coverage.

Describe if there is any unusual behaviour of your code(Write NA if there isn't)

A clear and concise description of it.

Checklist:

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

Screenshots (if any)

Original Updated
original screenshot updated screenshot

Signed-off-by: EraKin575 <tejaskumar574@gmail.com>
Copy link

sweep-ai bot commented Nov 3, 2023

Apply Sweep Rules to your PR?

  • Apply: All new business logic should have corresponding unit tests.
  • Apply: Refactor large functions to be more modular.

Copy link

@nakulbh nakulbh left a comment

Choose a reason for hiding this comment

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

Looks good to me

@AkashKumar7902
Copy link
Member

What if the next port is in use by some other running service? A while loop with a random function to generate port would be better I believe

Signed-off-by: EraKin575 <tejaskumar574@gmail.com>
Copy link
Member

@charankamarapu charankamarapu left a comment

Choose a reason for hiding this comment

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

Please address the comments

pkg/proxy/proxy.go Outdated Show resolved Hide resolved
Signed-off-by: EraKin575 <tejaskumar574@gmail.com>
Copy link
Member

@charankamarapu charankamarapu left a comment

Choose a reason for hiding this comment

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

Please address the comment

pkg/proxy/proxy.go Show resolved Hide resolved
Signed-off-by: EraKin575 <tejaskumar574@gmail.com>
Copy link
Member

@charankamarapu charankamarapu left a comment

Choose a reason for hiding this comment

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

Please address the comments, rest looks fine.

for i := 1024; i <= 65535 && attemptsDone < maxAttempts; i++ {
if isPortAvailable(uint32(i)) {
opt.Port = uint32(i)
logger.Info(Emoji+"Port %v is already in use, switching to next available port");
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need emoji here it is already appended when we initialise logger and include the port number which you are switching to in the log.

}

if maxAttempts<=attemptsDone{
logger.Error(Emoji+"Failed to find an available port to start proxy server")
Copy link
Member

Choose a reason for hiding this comment

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

Remove the emoji.

}
}

if maxAttempts<=attemptsDone{
Copy link
Member

Choose a reason for hiding this comment

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

beautify the statement I guess there must be spaces before and after the <= symbol. There must be some extension in the IDE you can use it and make sure it is indentation is correct.

Signed-off-by: EraKin575 <tejaskumar574@gmail.com>
Copy link
Member

@charankamarapu charankamarapu left a comment

Choose a reason for hiding this comment

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

Please address the comment.

//IPv4
localIp4, err := util.GetLocalIPv4()
if err != nil {
log.Fatalln(Emoji+"Failed to get the local Ip4 address", err)
log.Fatalln("Failed to get the local Ip4 address", err)
Copy link
Member

Choose a reason for hiding this comment

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

Why is it removed from here? This is not zap.logger, It is just log. Here we should use emoji.

Signed-off-by: EraKin575 <tejaskumar574@gmail.com>
Signed-off-by: EraKin575 <tejaskumar574@gmail.com>
Signed-off-by: EraKin575 <tejaskumar574@gmail.com>

if !isPortAvailable(opt.Port) {
logger.Info("Port is already in use, switching to next available port",zap.Uint32("port",opt.Port));
Copy link
Member

@charankamarapu charankamarapu Nov 9, 2023

Choose a reason for hiding this comment

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

Port is already in use, switching to next available port {port : 16789} this is how the logger looks when you run keploy. It gives a sense that you found that the port is already in use and you are switching to port 16789 which is wrong. You can delete this log or correct it . Deleting this log makes more sense for me.

EraKin575 and others added 2 commits November 10, 2023 14:02
Signed-off-by: EraKin575 <tejaskumar574@gmail.com>
Copy link
Member

@charankamarapu charankamarapu left a comment

Choose a reason for hiding this comment

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

ship it!

@charankamarapu charankamarapu merged commit 7f8c5a2 into keploy:main Nov 10, 2023
6 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2023
@EraKin575 EraKin575 deleted the dev/portChange branch November 10, 2023 12:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add automatic port change if the port is busy
4 participants