Repository navigation
fix(webconfig): rebind port 80 right after a stop - #97
Merged
Merged
Conversation
A closed HTTP connection holds port 80 in TIME_WAIT for 2*MSL, so the next listen fails with ERR_USE. Set SOF_REUSEADDR on the new pcb before tcp_bind, and only for port 80, via a linker wrap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After
stop webconfig, starting anything on port 80 again (start webconfigorstart ota) could fail for up to 120 s withbind error: -8(ERR_USE), and the server did not come up.The listener is not what holds the port. The last accepted HTTP connection sits in TIME_WAIT for 2 x MSL (120 s here), and lwIP's
tcp_bindonly ignores a TIME_WAIT pcb when the new pcb hasSOF_REUSEADDR. AsyncTCP never sets it.Fix
Set
SOF_REUSEADDRon the pcb before a bind to local port 80.-Wl,--wrap=tcp_bindin[esp32_base], next to the existingdns_gethostbynameandesp_transport_ws_initwraps.src/helpers/ESP32TcpBindReuse.cpp:__wrap_tcp_bindsets the option whenport == 80, then calls the realtcp_bind. Every other bind passes through unchanged.AsyncTCP calls
tcp_bindon the lwIP thread (tcpip_api_call), so the wrap takes no lock. Accepted connections inherit the option from the listener.Testing
heltec_v4_repeater_observer_mqtt,Heltec_v3_repeater_observer_mqtt,Station_G3_ESP32_repeater_observer_mqtt,Heltec_v3_repeater._tcp_bind_apicalls__wrap_tcp_bind.start ota3 s after the stop -> webconfig -> webconfig -> ota, with curl connections before each stop. Every start served (/200,/update200), nobind error, all five slots stayed connected.Not tested: V3, Station G3 and Ethernet boards on hardware; a same-day control run on the unfixed build (the failure is from earlier bench sessions).