arduino-libraries / Ethernet

Ethernet Library for Arduino
http://arduino.cc/
259 stars 264 forks source link

Set socket to MAX_SOCK_NUM if connection fails #208

Open goccert25 opened 2 years ago

goccert25 commented 2 years ago

I've been experiencing a bug using the Arduino to communicate over ethernet when using multiple EthernetClients, and as far as I can tell this line is the culprit. The exact steps of how the bug happens:

This change should fix the bug, because instead of returning 0 on line 63 we break, we set _socketIndex back to MAX_SOCK_NUM and everything behaves as expected.

goccert25 commented 2 years ago

@karlsoderby @per1234 , this is my first time contributing to the Arduino ecosystem. Please let me know if there's anything missing from the PR or anything else you'd like to see from me :)

github-actions[bot] commented 2 years ago

Memory usage change @ ec1ed04edf352ea44481ddcd81b89efd3b47d684

Board flash % RAM for global variables %
arduino:avr:leonardo 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:mega 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:nano :green_heart: -2 - 0 -0.01 - 0.0 0 - 0 0.0 - 0.0
arduino:megaavr:nona4809 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:megaavr:uno2018 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:sam:arduino_due_x_dbg :small_red_triangle: 0 - +8 0.0 - 0.0 N/A N/A
arduino:samd:arduino_zero_edbg :small_red_triangle: 0 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkr1000 :small_red_triangle: 0 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrfox1200 :small_red_triangle: 0 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrgsm1400 :small_red_triangle: 0 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrnb1500 :small_red_triangle: 0 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrvidor4000 :small_red_triangle: 0 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1300 :small_red_triangle: 0 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1310 :small_red_triangle: 0 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwifi1010 :small_red_triangle: 0 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrzero :small_red_triangle: 0 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:nano_33_iot :small_red_triangle: 0 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table Board|examples/AdvancedChatServer
flash|%|examples/AdvancedChatServer
RAM for global variables|%|examples/BarometricPressureWebServer
flash|%|examples/BarometricPressureWebServer
RAM for global variables|%|examples/ChatServer
flash|%|examples/ChatServer
RAM for global variables|%|examples/DhcpAddressPrinter
flash|%|examples/DhcpAddressPrinter
RAM for global variables|%|examples/DhcpChatServer
flash|%|examples/DhcpChatServer
RAM for global variables|%|examples/LinkStatus
flash|%|examples/LinkStatus
RAM for global variables|%|examples/PagerServer
flash|%|examples/PagerServer
RAM for global variables|%|examples/TelnetClient
flash|%|examples/TelnetClient
RAM for global variables|%|examples/UDPSendReceiveString
flash|%|examples/UDPSendReceiveString
RAM for global variables|%|examples/UdpNtpClient
flash|%|examples/UdpNtpClient
RAM for global variables|%|examples/WebClient
flash|%|examples/WebClient
RAM for global variables|%|examples/WebClientRepeating
flash|%|examples/WebClientRepeating
RAM for global variables|%|examples/WebServer
flash|%|examples/WebServer
RAM for global variables|% -|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|- arduino:avr:leonardo|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0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|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0 arduino:samd:mkrwan1310|4|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0|0|0.0|0|0.0|4|0.0|0|0.0|0|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0 arduino:samd:mkrwifi1010|4|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0|0|0.0|0|0.0|4|0.0|0|0.0|0|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0 arduino:samd:mkrzero|4|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0|0|0.0|0|0.0|4|0.0|0|0.0|0|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0 arduino:samd:nano_33_iot|4|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0|0|0.0|0|0.0|4|0.0|0|0.0|0|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0|4|0.0|0|0.0
Click for full report CSV ``` Board,examples/AdvancedChatServer
flash,%,examples/AdvancedChatServer
RAM for global variables,%,examples/BarometricPressureWebServer
flash,%,examples/BarometricPressureWebServer
RAM for global variables,%,examples/ChatServer
flash,%,examples/ChatServer
RAM for global variables,%,examples/DhcpAddressPrinter
flash,%,examples/DhcpAddressPrinter
RAM for global variables,%,examples/DhcpChatServer
flash,%,examples/DhcpChatServer
RAM for global variables,%,examples/LinkStatus
flash,%,examples/LinkStatus
RAM for global variables,%,examples/PagerServer
flash,%,examples/PagerServer
RAM for global variables,%,examples/TelnetClient
flash,%,examples/TelnetClient
RAM for global variables,%,examples/UDPSendReceiveString
flash,%,examples/UDPSendReceiveString
RAM for global variables,%,examples/UdpNtpClient
flash,%,examples/UdpNtpClient
RAM for global variables,%,examples/WebClient
flash,%,examples/WebClient
RAM for global variables,%,examples/WebClientRepeating
flash,%,examples/WebClientRepeating
RAM for global variables,%,examples/WebServer
flash,%,examples/WebServer
RAM for global variables,% arduino:avr:leonardo,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:avr:mega,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:avr:nano,-2,-0.01,0,0.0,-2,-0.01,0,0.0,-2,-0.01,0,0.0,0,0.0,0,0.0,-2,-0.01,0,0.0,0,0.0,0,0.0,-2,-0.01,0,0.0,-2,-0.01,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,-2,-0.01,0,0.0,-2,-0.01,0,0.0,-2,-0.01,0,0.0 arduino:megaavr:nona4809,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:megaavr:uno2018,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.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,4,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,4,0.0,0,0.0,4,0.0,0,0.0,4,0.0,0,0.0 ```
goccert25 commented 1 year ago

Hey @karlsoderby @per1234, bumping this. Is there anyway to move this PR forward?

per1234 commented 1 year ago

There is an alternative proposal at https://github.com/arduino-libraries/Ethernet/pull/176