You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we were to just telnet into both, the program would print "ok" and close both connections.
However, we can only connect on the first.
The second is stuck at SYN_WAIT.
Description
No response
Additional information
This is needed to properly implement PASV for ftp.
ACTIVE with a bind & a connection, works just fine.
#!/usr/bin/env python3importsocketimporttimeimportrandom# edit host and port to match serverHOST="192.168.6.198"PORTS= (20, 21)
TIMEOUT=5INTERVAL=1whileTrue:
PORT=random.choice(PORTS) # just for funprint("Create TCP Client Socket")
withsocket.socket(socket.AF_INET, socket.SOCK_STREAM) ass:
s.settimeout(TIMEOUT)
print("Connecting")
s.connect((HOST, PORT))
size=s.send(b'Hello, world')
print(f"Sent {size} bytes to {HOST}:{PORT}")
time.sleep(INTERVAL)
edit: I guess b/c only one is connected at a time, may be a useful workaround
watch -n0.2 'netstat | grep "board-ip-here"' to monitor all connections and their status.
The second one, as stated above is stuck at SYN_WAIT.
It could just be a oopsie, sending the SYN response to the wrong connection for all I know.
Auto-reload is off.
code.py output:
Accepting 1
Accepting 2
Accepted 2
ok
Code done running.
And dolphin w/PASV doesn't work with it, even if the cli does.
So it can't be used as a workaround.
PASSIVE (PASV)
This command requests the server-DTP to "listen" on a data
port (which is not its default data port) and to wait for a
connection rather than initiate one upon receipt of a
transfer command. The response to this command includes the
host and port address this server is listening on.
Passing everythin over the control port isn't something ftp is designed for it so seems.
There does seem to be an espressif bug when attempting simultaneous TCP connections (2 accepts in a row on different ports, without closing either) - your 1st example above and the original example.
I fully expect sequential (close before next connect) connections (to the same or different ports) to work (your 3rd example, and my asyncio example). I wouldn't expect 2 servers on the same port to work (your 2nd example).
But PASV doesn't work with sequential connection to the control port, then the data port?
There does seem to be an espressif bug when attempting simultaneous TCP connections (2 accepts in a row on different ports, without closing either)
I think it would be good to test this with, say, MicroPython on some ESP32xx board to see if it is our issue or is ESP-IDF. Also maybe a quick search of the ESP-iDF issues.
I did plently of esp debugging.
I only however managed to down as far as lwip_accept in ports/espressif/common-hal/socketpool/Socket.c:272.
With esp_log we can see there, the 2nd/3rd socket not being accepted.
I tried going deeper, but the internal logging of lwip doesn't get printed no matter what I do.
Importing esp_log, is a mess I cannot figure out.
I will have to leave it you you guys from there on out.
(Perhaps C3 can prove itself not being a paperbrick and help with some jtag?)
Activity
anecdata commentedon Sep 5, 2023
Had to tweak the
close(). Then it works onraspberrypi, butespressifgets stuck in_socket2.accept()(client times out on connect).server code.py
anecdata commentedon Sep 5, 2023
works in
asyncioon both platforms:server code.py
CPython client code for both cases above
edit: I guess b/c only one is connected at a time, may be a useful workaround
bill88t commentedon Sep 5, 2023
watch -n0.2 'netstat | grep "board-ip-here"'to monitor all connections and their status.The second one, as stated above is stuck at
SYN_WAIT.It could just be a oopsie, sending the SYN response to the wrong connection for all I know.
Regarding asyncio, I drafted this:
Which as you see, also doesn't work.
Something to note:
Is also a nono.
But:
Works just fine..
And dolphin w/PASV doesn't work with it, even if the cli does.
So it can't be used as a workaround.
Passing everythin over the control port isn't something ftp is designed for it so seems.
anecdata commentedon Sep 5, 2023
There does seem to be an
espressifbug when attempting simultaneous TCP connections (2 accepts in a row on different ports, without closing either) - your 1st example above and the original example.I fully expect sequential (close before next connect) connections (to the same or different ports) to work (your 3rd example, and my
asyncioexample). I wouldn't expect 2 servers on the same port to work (your 2nd example).But PASV doesn't work with sequential connection to the control port, then the data port?
dhalbert commentedon Sep 5, 2023
I think it would be good to test this with, say, MicroPython on some ESP32xx board to see if it is our issue or is ESP-IDF. Also maybe a quick search of the ESP-iDF issues.
bill88t commentedon Sep 5, 2023
PASV tl;dr workflow explanation:
.listen()).This whole time, the control connection remains open and in use.
If we close it, the client aborts. I did try.
bill88t commentedon Sep 5, 2023
New discovery!
If the web workflow is disabled, you can do 2 binds.
So in reality you cannot do 3 binds.
[-]ESP LWIP network stack cannot handle 2 binds correctly[/-][+]ESP LWIP network stack cannot handle 3 binds correctly.[/+]bill88t commentedon Sep 5, 2023
Taking the same code and adding:
in it, is all that is required to trigger the bug.
.listen()does not affect it.This gives me some good clues as to where to look.
bill88t commentedon Sep 5, 2023
I did plently of esp debugging.
I only however managed to down as far as
lwip_acceptinports/espressif/common-hal/socketpool/Socket.c:272.With esp_log we can see there, the 2nd/3rd socket not being accepted.
I tried going deeper, but the internal logging of lwip doesn't get printed no matter what I do.
Importing esp_log, is a mess I cannot figure out.
I will have to leave it you you guys from there on out.
(Perhaps C3 can prove itself not being a paperbrick and help with some jtag?)
bill88t commentedon Sep 10, 2023
I went and put micropython 1.20 on one of my s2 boards, and this is not reproducible.
I opened 4 sockets and connected to them successfully.
bill88t commentedon Apr 14, 2024
This issue is fully resolved.