it deadlocks because you're not reading all the data. Read() may return "up to len(p)", but not necessarily the whole thing. the reader should loop until it reads all available bytes in your case you know how many bytes you are going to write beforehand.
if you do not ignore the first value returned from Read() and Write() it will become very obvious. On Fri, Mar 9, 2018 at 8:44 AM, <pierspowlesl...@gmail.com> wrote: > Hi all > > I've written a simple program which simply sends a message across a tcp > connection and back again. > > For some reason when I make the buffer larger than a certain size the > program deadlocks. > > When run on the playground with datalen set to 10000 the program deadlocks > but with datalen set to 1000 it functions fine. On my local machine it > deadlocks with datalen set to 1e7 but is fine with datalen set to 1e6. > > The program in question is here https://play.golang.org/p/q7QWA4Uz-3H > > Please could someone shed some light onto this, I'm literally going nuts ;) > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.