Gotchas with coding on remote machine with VS Code

I started trying out working on code on my remote machine (DigitalOcean Ubuntu droplet) using VS Code on my Windows 10 system a few days ago. Most of the instructions here are ok. A few things might be considered missing though.

In this piece, I cover only the problems I experienced.

Authentication problem

The first problem that struck was, after you set up the authentication keys, you're supposed to "Run Remote-SSH: Connect to Host... from the Command Palette (F1)..." (Connect to a remote host, step 2).

It didn't work. And unless you press CTRL + ` to show the terminal inside VS Code, you won't know why. I think, for me it even said something very close to "setting up ssh host: (details). initialising." But when I clicked on "details", nothing happened. When I opened the terminal, I saw that it was waiting for me to enter the password to my remote machine.

So, while authentication keys had been properly set up, two more things were needed. First, go through the next section in the docs: "Remembering hosts you connect to frequently". I know you're not supposed to strictly need this section but, well, chances are you do.

Second, open the Command Palette., look for Remote-SSH. One of the options is Open Configuration File. Click that, and Settings comes up as an option. Click that and enter "The absolute file path to a custom SSH config file", which you should now have after the step above.

After that, you should be able to connect quite smoothly. For the most part anyway.

Connection keeps breaking

This sometimes happened to me, especially when I reloaded VS Code or restarted my computer. Then it kept reconnecting. Sometimes it looked like I had 4 parallel connections to my remote machine. And then I couldn't open bash within the terminal in VS Code.

I don't know how to solve this problem. I just closed VS Code and waited for a while, I guess. Sometimes, it took a while, like the next day, before things were back to normal and I could for the most part have just a single connection without the constant reconnecting.

It sounds horrible but in practice it's been ok. This happened only once in a while.

Memory runs out

A more pressing problem for me was that after coding a while and running, closing, and rerunning my Golang program a few times, the machine said "fatal error: runtime: out of memory". It refused to run my program anymore.

I think this is in part because I was already serving a few other websites from the same droplet. Running free -h showed that, yeah, most of my memory was already in play.

What puzzled me, though, was that memory wasn't being returned to the machine whenever I closed the program. After a bit of reading, I now think that memory is only returned when another application asks for it. But that maybe doesn't explain why I couldn't rerun the same program and get back and use that same memory.

Anyway, my first thought was to run the program in a Docker container and kill and remove it every time I needed to test changes to my program. But it didn't work. I didn't have enough memory for that, I suppose.

So, I made a swap file. Instructions here. The page warns that it's not healthy for SSD's to use swap files but I'm poor because nobody wants to employ junior developers without a computer science background so I don't have the cash to upgrade. But at the same time I'm expected to acquire skills and experience. So. Something's gotta give. I don't use it that much anyway. I think.

Anyway, the swap file works fine and memory seems to be released from it faster than from RAM. It's rare that it doesn't but when that happens I just run swapoff -a and then swapon -a to clear it. You can use free -h to see the difference.

Conclusion

Some things don't work as fluidly as before. Like, Golang automatically formats my code whenever I save on my local machine but on the remote host, I have to run gofmt on the file. And I have to use sudo when using git and there's a noticeable but very minor lag, but these are super minor inconveniences.

I really like that I'm coding directly in a deploy environment with HTTPS and WSS enabled so problems related to this environment are surfaced instantly. It makes the development process a lot faster.

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required