0

When calling Cap'n Proto's writeMessageToFd(pipe, message); I get this error:

terminate called after throwing an instance of 'kj::ExceptionImpl'
  what():  src/kj/io.c++:323: failed: ::writev(fd, current, iov.end() - current): Bad file descriptor; fd = -1
stack: 0x7efead69cf89 0x7efead6a0c7f 0x7efead6a2648 0x7efead6a24f7 0x7efead8f40b7 0x7efead8f42a4 0x402c7b 0x402a36 0x4028df 0x7efeabd50e50 0x7efeabd5181a 0x7efeabd52669 0x7efeabd52a03 0x7efeabd52bb2 0x402865 0x4027ab
BAR
  • 15,909
  • 27
  • 97
  • 185

1 Answers1

1

You've not really asked a question, but I can tell you from that exception that you shouldn't have attempted to call writeMessageToFd with an invalid file descriptor (the exception text tells you this "Bad file descriptor; fd = -1").

You have two options: - don't call that function if pipe == -1 (probably best, you should really have checked that the call which returned pipe didn't return -1) - surround your call to writeMessageToFd() with a try/catch and handle the exception appropriately

You should really go with the former and handle a -1 value in pipe appropriately.

Mahadev
  • 856
  • 1
  • 17
  • 44
aho
  • 304
  • 2
  • 11
  • Yes it was an invalid fd. – BAR Aug 13 '15 at 16:02
  • Just to note this also happens when there is any error with the stream. Cap'n Proto seems to be a reliable serializer, so check your code first. – BAR Aug 16 '15 at 23:52