libp2p / go-libp2p-examples

Example libp2p applications
MIT License
338 stars 145 forks source link

Problem with debugging the chat example #7

Open Xeneou opened 6 years ago

Xeneou commented 6 years ago

Compiling and running the binaries works fine. However, when I try to debug the code I get a panic on the server side, immediately after the client connects.

Panic:

Run './chat -d /ip4/127.0.0.1/tcp/3001/ipfs/QmcxsSTeHBEfaWBb2QKe5UZWK8ezWJkxJfmcb5rQV374M6' on another console.
 You can replace 127.0.0.1 with public IP as well.

Waiting for incoming connection

2018/08/13 15:27:23 Got a new stream!
> panic: EOF

goroutine 37 [running]:
main.writeData(0xc42043a0c0)
    /home/me/go/Workspace4/src/github.com/libp2p/go-libp2p-examples/chat/chat.go:122 +0x36b
created by main.handleStream
    /home/me/go/Workspace4/src/github.com/libp2p/go-libp2p-examples/chat/chat.go:94 +0x190

Debugger finished with exit code 0

Problems seems to be that the stdReader in writeData() receives no bytes in stdReader.ReadString('\n')

Can somebody explain/reproduce this or has a solution? Debugging would be nice to follow and understand the program's control flow. (Debugging of the echo example works and doesn't cause a panic.)

go env https://gist.githubusercontent.com/Xeneou/49411ca2a96c0792d4f3d5efac807b7d/raw/9d5ad32802ffb9112a5aab07ac311e7bb54f8fca/details.md

go-libp2p-examples/chat 513da5f2d111eec90b562725015fa04f1cd139e5

go-libp2p libp2p/go-libp2p@163d7d40dd00bf4c275a164d60fc55e3a34a6073

raulk commented 5 years ago

@Xeneou how exactly are you starting the debugger? (delve)

JackBekket commented 5 years ago

I has experienced such behavior when I have tried android build, and in my case it was because of android doesn't have an os.StdIn interface for concole direct input.

So, my suggestion is to check interface in stdReader := bufio.NewReader(os.Stdin) in func writeData(rw *bufio.ReadWriter)