Commit b3cfd6be authored by Kenton Varda's avatar Kenton Varda

Warn if AsyncOutputStream::write()'s result promise is unused.

It turns out that, quite often, the write() will have already completed before the method returns, hence dropping the returned promise won't cause any apparent problem -- until you try to write() a sufficiently large value that it doesn't complete on the first call. Then, you get mysterious bugs.

Indeed, it turns out the HTTP library has such bugs, which are fixed in this change.
parent 6643b805
......@@ -86,8 +86,9 @@ class AsyncOutputStream {
// Asynchronous equivalent of OutputStream (from io.h).
public:
virtual Promise<void> write(const void* buffer, size_t size) = 0;
virtual Promise<void> write(ArrayPtr<const ArrayPtr<const byte>> pieces) = 0;
virtual Promise<void> write(const void* buffer, size_t size) KJ_WARN_UNUSED_RESULT = 0;
virtual Promise<void> write(ArrayPtr<const ArrayPtr<const byte>> pieces)
KJ_WARN_UNUSED_RESULT = 0;
virtual Maybe<Promise<uint64_t>> tryPumpFrom(
AsyncInputStream& input, uint64_t amount = kj::maxValue);
......
......@@ -1297,7 +1297,7 @@ public:
KJ_REQUIRE(inBody) { return kj::READY_NOW; }
auto fork = writeQueue.then([this,buffer,size]() {
inner.write(buffer, size);
return inner.write(buffer, size);
}).fork();
writeQueue = fork.addBranch();
......@@ -1308,7 +1308,7 @@ public:
KJ_REQUIRE(inBody) { return kj::READY_NOW; }
auto fork = writeQueue.then([this,pieces]() {
inner.write(pieces);
return inner.write(pieces);
}).fork();
writeQueue = fork.addBranch();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment