JavaScript and the Single Threaded Lie

August 5th, 2016

JavaScript is single threaded

Yes, but.. it is also heavily asynchronous. Since my experience porting Node.js to new platforms, it’s turned into one of my go to languages for hacking web apps. Unfortunately I still fall into the async trap.

Let’s look at some code:

And here is the output of the code if we run it:

Now, in this example – it’s pretty clear what is causing the issue. The setTimeout() is doing a delay of 2 seconds. This is an async call, so the for loop has completed it’s entire cycle before any of the callbacks get a chance to run. Timing issues also make things more confusing if things sometimes work since you can’t guarantee the order of asynchronous functions.

The trap for me, is when the code is more complex and it isn’t obvious to see that there is an async call in the way. Also, my brain keeps telling me that for each iteration through the loop, I (think I’m) creating a new variable (item) and that should provide correct isolation for the state.

There are two simple solutions to this problem.

Solution 1 – use the call stack:

Move the async call myFunction into a helper and pass the value to it. This moves it from being a local variable to one on the stack (as a parameter to helper).

Solution 2 – have the callback give the value back:

To be honest, solution 2 is just another call stack approach – but it’s a different enough pattern to be a second solution.

The output of both good solutions looks like:


Bosch Error 43

July 20th, 2016

It’s happened more than once, the over full pot of boiling water on the stove – you add whatever it is that you’re going to boil and splash. Boil over and water on the stove top. With a gas stove sometimes the burner will go out, others you’re lucky and you just get some really hot water on the hot top of your stove.

Not a big deal.. until you have too much water as we did the other day. It ran down the front of the stove a little, some even made it to the floor. Clean up the mess and forget about it.

Except this one time recently, the stove display started blinking the lock icon.

Searching found stuff like: remove the stove from power for 5 minutes, then plug it back in to reset.

When I tried that solution, you could hear the oven doing a reset cycle and trying to lock/unlock the door several times. Sometimes it would stay locked, and I’d do another power cycle and then it’d stay unlocked. Things did not improve. Still the flashy lock.

I found a service manual that was close, but the removal of the front panel was different than shown there. I needed to remove some obvious screws from just under the lip – then pull the stove out to get to a pair (on each side) of screws that held the front panel on.

After disassembling the panel, it was clear we had some water down there – but not much. I cleaned up the board verified things were dry and re-assembled. Still the lock problem.

Two days later, the oven light started to go on by itself. You could turn it off — and shortly after it’d turn itself back on. The following morning, a power cycle resolved the Error 43. I was able to cook some bacon in the oven. During this, the oven got a bit funky. The light wasn’t coming on when you opened the door — then it would intermittently come on and off when you opened the door.

My theory is that the heat of the oven was helping dry out the moisture from wherever it got to. After finishing with the bacon, the flashing lock was back.

One more power cycle the next day – and the oven seems to have started to work “like normal” again. I’m fairly confident at this point that the issue was some water got into one of the switches (probably the locking mechanism) and was shorting out a sensor there. However, as the door light was also affected, I suspect there was multiple sensors affected.

Thankfully it was ‘clean’ water (vs. a mucky sauce) and seems to have dried up removing any issues.

Lesson learned: don’t let water accumulate on the cook top of your Bosch stove/oven. If you do get Error 43 – be patient and dry it out. A power cycle will help once things are dry enough.

SSL for everybody

April 28th, 2016


SSL certificates are a great way to ensure that the website you’re connected to is really the one you think you’re connected to, and it also keeps the traffic between your client and the server secure. The HTTPS protocol uses SSL certificates. The main problem with the SSL infrastructure was that you needed to get one that was signed by one of the central trusted authorities – and generally if you wanted one of these you had to pay for one. There were a few places that would give you a free certificate for personal use, the other alternative was to use a self signed certificate but there were usability issues because it isn’t signed by a trusted authority.

This all changed recently with Let’s Encrypt – you can now get a free certificate with very little effort. If you maintain a website or host an app, you should check out. The remainder of this post is a cleaned up set of notes on what I did.

I started out here – which seemed to be a good starting point. Then I figured I’d make sure my server met the criteria they had for support, the documentation had some details covering this. I was happy to see Ubuntu 12.04+ and Apache 2.x support, so this made me fairly confident my server was supported.

But.. my Ubuntu doesn’t seem to have a letsencrypt package

No problem, we’ll just follow along with

The last command, while asking for help – will do some bootstrapping of let’s encrypt. So don’t skip it. The scripts include calls to sudo, so you don’t have to be root to run them but it will ask for root access.

[Security note – it is always a little bit scary running random scripts, always worth looking at them. There is a growing trend of having “wget -O – | bash” be normal, but you should be afraid]

Some exciting updates to my server from doing just the bootstrap. My /etc/ca-certificates got updated (it was probably way overdue), it also dragged me up to date for libssl. It took a while to finish, but we finally got the help screen.

At this point, I have the let’s encrypt tools installed on my server, so time to try them out.

Hopefully the following command is going to register us and get a new certificate for my old expired one.

Well that didn’t work, it picked up some ‘other’ domains I host — but not my main one. Weird, but probably due to my non-standard configuration of Apache due to years of hacking it. It was easy to bail out so no harm done. Let’s try this then:

Ok – much better, email sign up and an agreement (which yes, I took the time to read – it was only 6 pages).  It seems as I don’t have a virtual host setup for and needed to manually pick the apache config file (not a big deal), this was why the first try didn’t work.

Visiting shows no more certificate error (woot!) and all looks good. It was really this easy.

The end of the script even suggests you visit: to check for issues.  These SSL Labs tests, show that my certificate from letsencrypt will expire in just under 3 months, so I’ll want to add a cron job to do a renew. They also gave me a B rating, with lots of gorpy details on why.

To renew, I just need to run this command from time to time

That’s really easy to do with cron – so I added an entry to my root user crontab to run this once a month.