Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix nil pointer exception when calling Start again after address binding error #2131

Merged
merged 1 commit into from
Mar 15, 2022

Conversation

tehsphinx
Copy link
Contributor

@tehsphinx tehsphinx commented Mar 14, 2022

There is a nil pointer exception because the code assigns a nil value to an interface (e.Listener) which ends up creating a non-nil interface containing a nil pointer. Using this will result in the nil pointer exception and checking the e.Listener against nil will be false -- which is why the Listener is not recreated and overwritten the during the second call to Start.

Small code example that triggers this error (given an existing echo router):

if err := e.Start(":6060"); err != nil {
	// retry with random port
	if r := e.Start(":"); r != nil {
		log.Fatal(r)
	}
}

@codecov
Copy link

codecov bot commented Mar 14, 2022

Codecov Report

Merging #2131 (8bcff16) into master (b445958) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2131   +/-   ##
=======================================
  Coverage   92.10%   92.11%           
=======================================
  Files          37       37           
  Lines        3028     3030    +2     
=======================================
+ Hits         2789     2791    +2     
  Misses        150      150           
  Partials       89       89           
Impacted Files Coverage Δ
echo.go 95.17% <100.00%> (+0.03%) ⬆️

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 b445958...8bcff16. Read the comment docs.

Copy link
Contributor

@aldas aldas left a comment

Choose a reason for hiding this comment

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

LGTM

@aldas aldas merged commit 05df10c into labstack:master Mar 15, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants