main.cpp: Work around a weird edge-case bug.

This commit is contained in:
ZmnSCPxj jxPCSnmZ 2022-05-01 11:17:32 +08:00
parent 0a7ffea73c
commit d3eb1a190f

View file

@ -26,5 +26,35 @@ Ev::Io<int> io_main(int argc, char **argv) {
}
int main (int argc, char **argv) {
return Ev::start(io_main(argc, argv));
/* For some reason, doing a direct Ev::start(io_main(argc, argv));
* results in a crash under an edge-case condition.
* This edge-case condition is if data is immediately fed to
* the stdin of clboss.
* You can tickle it (reverting to Ev::start(io_main(argc, argv))
* and recompiling first) with this:
*
* echo '{"id": 0, "method": "getmanifest", "params": {}}' | ./clboss
*
* Note that if you just invoke clboss and input the above text
* manually, it will work perfectly fine, since most humans have
* reflex times measurable in dozens or hundreds of milliseconds.
*
* This does not normally happen in the usual case since the
* lightningd usually takes a bit of time before it actually
* emits the getmanifest call, and that is sufficient for the
* bug to leave the edge-case condition.
* On the other hand, a Sufficiently Fast (TM) processor might
* re-tickle this bug someday in the future even when run on
* some lightningd.
*
* This may be a bug in the C++ library or GCC itself, not
* CLBOSS.
* Why?
* Because the crash reports an error somewhere in the guts of
* malloc, and if you run clboss through valgrind, it does not
* crash even with the direct Ev::start(io_main(argc, argv)).
* valgrind works by replacing the malloc implementation, so ---
*/
auto code = io_main(argc, argv);
return Ev::start(code);
}