August 1, 2019
I’ve had the opportunity to spend some time on the tools with my current client, and it’s been fun.
Today’s bug hunt: we had a Dockerised NodeJS app that was coming up in dev, but not production. Everything seemed to start okay, but the ELB couldn’t see the app.
After flailing around for half an hour, my pair and I spotted the problem:
process.env.HTTP_PORT | 3000
0 when performing bitwise operations, because of course it does.
So the code ‘worked’ in dev, where
> process.env.HTTP_PORT undefined > process.env.HTTP_PORT | 3000 3000
But run it w/
HTTP_PORT set (to something other than
> process.env.HTTP_PORT '5000' > process.env.HTTP_PORT | 3000 7096
I say something other than
3000, because of course that behaves as you’d … expect? … given that
3000 | 3000 is just
> process.env.HTTP_PORT '3000' > process.env.HTTP_PORT | 3000 3000
Leaving aside the craziness that is allowing bitwise OR on a string by coercing the string into a number, this is why the app wasn’t coming up.
Well, it was, but on port
7096, where the ELB couldn’t find it. We corrected the typo from
|| and everything worked.
FWIW this is just grist for my “don’t default environment variables” mill.