go-serial icon indicating copy to clipboard operation
go-serial copied to clipboard

nativeGetPortsList hangs for 30 seconds on unix.Close(port.handle)

Open dstahlke opened this issue 3 years ago • 1 comments

This happens for me on Linux when trying to upload an Arduino sketch using arduino-cli. When nativeGetPortsList opens /dev/ttyS0, then closes it, the close syscall hangs for 30 seconds. As soon as the close syscall starts, /dev/ttyS0 disappears from /proc/$(pgrep arduino-cli)/fd. But the syscall doesn't return for 30 seconds. Stack trace:

#0  syscall.Syscall () at /usr/lib/go-1.13/src/syscall/asm_linux_amd64.s:27
#1  0x000000000062f7a0 in golang.org/x/sys/unix.Close (fd=3, err=...) at /home/XXX/go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_linux.go:525
#2  0x0000000000d5343c in (*unixPort).Close (port=0xc00406dd10, ~r0=...) at /home/XXX/go/pkg/mod/go.bug.st/[email protected]/serial_unix.go:37
#3  0x0000000000d547e1 in st/serial.nativeGetPortsList (~r0=..., ~r1=...) at /home/XXX/go/pkg/mod/go.bug.st/[email protected]/serial_unix.go:249
#4  0x0000000000d558d7 in st/serial.GetPortsList () at /home/XXX/go/pkg/mod/go.bug.st/[email protected]/serial.go:63
#5  github.com/arduino/arduino-cli/arduino/serialutils.WaitForNewSerialPort.func1 (~r0=<optimized out>, ~r1=...) at /home/XXX/Desktop/arduino-cli/arduino/serialutils/serialutils.go:95
#6  0x0000000000d5568f in github.com/arduino/arduino-cli/arduino/serialutils.WaitForNewSerialPort (~r0=..., ~r1=...) at /home/XXX/Desktop/arduino-cli/arduino/serialutils/serialutils.go:106
#7  0x0000000000d55536 in github.com/arduino/arduino-cli/arduino/serialutils.WaitForNewSerialPortOrDefaultTo (defaultPort=..., ~r1=..., ~r2=...)
    at /home/XXX/Desktop/arduino-cli/arduino/serialutils/serialutils.go:78
#8  0x0000000000d58b4b in github.com/arduino/arduino-cli/commands/upload.runProgramAction (pm=0xc00038d480, sketch=0xc003e420c0, importFile=..., importDir=..., fqbnIn=..., port=..., programmerID=..., 
    verbose=false, verify=false, burnBootloader=false, outStream=..., errStream=..., ~r12=...) at /home/XXX/Desktop/arduino-cli/commands/upload/upload.go:328
#9  0x0000000000d56c27 in github.com/arduino/arduino-cli/commands/upload.Upload (ctx=..., req=0xc00058fcd0, outStream=..., errStream=..., ~r4=<optimized out>, ~r5=...)
    at /home/XXX/Desktop/arduino-cli/commands/upload/upload.go:56
#10 0x0000000000e13b90 in github.com/arduino/arduino-cli/cli/upload.run (command=<optimized out>, args=...) at /home/XXX/Desktop/arduino-cli/cli/upload/upload.go:95
#11 0x00000000009609ca in github.com/spf13/cobra.(*Command).execute (c=0xc000421340, a=..., err=...) at /home/XXX/go/pkg/mod/github.com/spf13/[email protected]/command.go:846
#12 0x00000000009616a9 in github.com/spf13/cobra.(*Command).ExecuteC (c=0xc000421340, cmd=<optimized out>, err=...)
    at /home/XXX/go/pkg/mod/github.com/spf13/[email protected]/command.go:950
#13 0x0000000000e16b65 in github.com/spf13/cobra.(*Command).Execute (c=<optimized out>) at /home/XXX/go/pkg/mod/github.com/spf13/[email protected]/command.go:887
#14 main.main () at /home/XXX/Desktop/arduino-cli/main.go:31

If I run cat /dev/ttyS0 from another terminal, this hang doesn't happen.

dstahlke avatar Mar 07 '21 19:03 dstahlke

Is the port a USB port of the Arduino board? or is it an USB-to-Serial adapter connected to the Arduino? Which board is?

Please write here the full go source code that reproduce the problem (possibly try to cut it down to the minimum needed to reproduce the issue).

cmaglie avatar Sep 06 '21 15:09 cmaglie