Skip to content

Commit 7a6be85

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

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/util/piped_process.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,30 @@ 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+
return WriteFile(
353+
child_std_IN_Wr, message.c_str(), message_size, &bytes_written, NULL);
354+
};
355+
if(!write_file())
353356
{
354357
// Error handling with GetLastError ?
355358
return send_responset::FAILED;
356359
}
360+
// `WriteFile` can return a success status but write 0 bytes if we write
361+
// messages quickly enough. This problem has been observed when using a
362+
// release build, but resolved when using a debug build or `--verbosity 10`.
363+
// Presumably this happens if cbmc gets too far ahead of the sub process.
364+
// Flushing the buffer and retrying should then succeed to write the message
365+
// in this case.
366+
if(bytes_written == 0)
367+
{
368+
FlushFileBuffers(child_std_IN_Wr);
369+
if(!write_file())
370+
{
371+
// Error handling with GetLastError ?
372+
return send_responset::FAILED;
373+
}
374+
}
357375
INVARIANT(
358376
message_size == bytes_written,
359377
"Number of bytes written to sub process must match message size.");

0 commit comments

Comments
 (0)