Debugging like you just tumbled down Fate's Wheel of Fortune (Image by Cayambe - Own work, CC BY-SA 3.0)
Since I was already using the Fetch API with
node-fetch in the async part of my library, I thought: why not build a
node-fetch under the hood like
(then-)request. Two days later, it was actually working, as far as I could tell. However, if I wanted to publish this horror I need some actual testing.
node-fetch has a nice test suite, I only needed to convert 194 test cases to use the synchronous API. Not fun work, but worth its while, maybe. Anyway, the first test cases worked, but then it got stuck on the first actual request.
This is were I have to introduce you to the Karmabug. You see, after some testing I figured out that only the combination of my
sync-fetch and the test server just... stopped. The arguments were correct, my
fetch works with
https://example.org and the test server works with
node-fetch, but this combination simply did not. Investigating either pointed to the other, and I had no idea what to do next.
That would make a good tweet, I thought. "Karma for making sync HTTP requests I guess." Literally two minutes later it hit me: that was exactly what was going on. The test server could not respond to the requests because the request itself was blocking the event loop.