Evan Martin (evan) wrote in evan_tech,
Evan Martin
evan
evan_tech

found my bug!

Not too interesting, but this has been bugging me for a week.

Been working on a toy program that proxies a TCP connection. It was working fine for some and then would mysteriously corrupt others; I spent a long time looking and it finally hit me, painfully obvious.

I had threads going in each way doing this in a loop:
 forward :: Socket -> Socket -> IO ByteString
 forward src dst = do
   buf <- recv src (16 * 2^10)
   send dst buf
   return buf
Network.Socket.ByteString.send of course returns an integer of how many bytes were actually sent; you need to loop if you want to be sure to send it all. (I had imagined this higher-level API was handling this looping for me, but it makes more sense that it wouldn't. It does however handle EINTR, so when I had glanced at the source in my desperation I did notice a loop, throwing me off the scent.) Sticking a loop around the send fixed everything.
Tags: haskell
Subscribe

  • more on bug tracking; distributed editing

    A few separate posts, all in the same area. 1) Most (all?) the distributed bug tracking software I've glanced at stores bugs in a directory, one…

  • dvcs and offline

    I got a couple of comments on that previous post that betray a bit of a misunderstanding about how collaborative projects work in the presence of…

  • distributed bug tracking

    Distributed bug tracking is the natural extension of distributed version control. Aside from the normal benefits of distributed version control, like…

  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 4 comments