Get on the bus, Gus

I booted into OS X today and tried running the unit tests for my PHP driver. It chugged away for a while, then gave me “bus error”. Great. Gotta love C error messages. I narrowed it down to when I insert 253 or more elements into MongoDB. Now, that number was suspiciously close to 256, but I couldn’t think why that would be. I tracked it to the encoding code, then to the _id class code, then to the _id generation code. Surprisingly, it was doing its “bus error” thing before any memory access, it was just reading a file. I suddenly realized that I wasn’t closing the file after reading it, fixed it, and it ran perfectly.

4 thoughts on “Get on the bus, Gus

  1. And, to those playing along at home (like me!) — 253 + stdout + stderr + stdin = 256, the number of entries in the file table it (apparently?) gives you.

    Now why the hell _that_ would be happening, though, seems like a coincidence, unless you open 1 connection per insert or something. If that’s the case, there’s bigger problems here, since it seems like they might be overlapping/not closing/not being reclaimed fast enough.

    Like

  2. And, to those playing along at home (like me!) — 253 + stdout + stderr + stdin = 256, the number of entries in the file table it (apparently?) gives you.

    Now why the hell _that_ would be happening, though, seems like a coincidence, unless you open 1 connection per insert or something. If that’s the case, there’s bigger problems here, since it seems like they might be overlapping/not closing/not being reclaimed fast enough.

    Like

  3. I was opening a connection every time I did an insert, and totally forgot to fclose it. Ah well, all better now. Interestingly enough, Linux has no max for number of open file handles (something I found out while fighting with sockets) so I guess it just keeps opening them until you run out of memory.

    Like

  4. I was opening a connection every time I did an insert, and totally forgot to fclose it. Ah well, all better now. Interestingly enough, Linux has no max for number of open file handles (something I found out while fighting with sockets) so I guess it just keeps opening them until you run out of memory.

    Like

Leave a comment