Skip to content

Commit b98515a

Browse files
thomasspriggsNlightNFotis
authored andcommitted
Work around piped process send problem
1 parent afc53d8 commit b98515a

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/util/piped_process.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,31 @@ piped_processt::send_responset piped_processt::send(const std::string &message)
348348
#ifdef _WIN32
349349
const auto message_size = narrow<DWORD>(message.size());
350350
DWORD bytes_written = 0;
351-
if(!WriteFile(
352-
child_std_IN_Wr, message.c_str(), message_size, &bytes_written, NULL))
351+
const auto write_file = [&]()
352+
{
353+
return WriteFile(
354+
child_std_IN_Wr, message.c_str(), message_size, &bytes_written, NULL);
355+
};
356+
if(!write_file())
353357
{
354358
// Error handling with GetLastError ?
355359
return send_responset::FAILED;
356360
}
361+
// `WriteFile` can return a success status but write 0 bytes if we write
362+
// messages quickly enough. This problem has been observed when using a
363+
// release build, but resolved when using a debug build or `--verbosity 10`.
364+
// Presumably this happens if cbmc gets too far ahead of the sub process.
365+
// Flushing the buffer and retrying should then succeed to write the message
366+
// in this case.
367+
if(bytes_written == 0)
368+
{
369+
FlushFileBuffers(child_std_IN_Wr);
370+
if(!write_file())
371+
{
372+
// Error handling with GetLastError ?
373+
return send_responset::FAILED;
374+
}
375+
}
357376
INVARIANT(
358377
message_size == bytes_written,
359378
"Number of bytes written to sub process must match message size.");

0 commit comments

Comments
 (0)