tailscale / tmemes

A meme generator for your tailnet!
BSD 3-Clause "New" or "Revised" License
42 stars 1 forks source link

Occasional panic during macro rendering #1

Closed creachadair closed 1 year ago

creachadair commented 1 year ago

On my local test instance, I occasionally get the attached panic during macro generation. I don't know exactly what triggers it, but this seems to work:

  1. Empty the macro cache (rm /tmp/tmemes/macros/*).
  2. Start up the server.
  3. Visit the macros page in the browser and force-reload.

Maisem and I speculate this may be related to trying to draw outside the image bounds somehow. However, interestingly if while the server is running you repeat step (1) and then (3), I have so far not been able to make it panic again in that way—and all the images get generated OK. This maybe suggests the rendering library is keeping some state that gets primed?

This is not causing a lot of problems in production, probably because the UI doesn't generate weird text positions the way some of my manual test data do.

panic.txt

creachadair commented 1 year ago

For the record, this is the macro spec:

{
  "id": 2,
  "templateID": 2,
  "creator": -1,
  "createdAt": "2023-04-01T21:02:23.841803Z",
  "textOverlay": [
    {
      "text": "belligerent badness",
      "field": {
        "x": 0.2,
        "y": 0.5
      },
      "color": "white",
      "strokeColor": "black"
    }
  ],
  "upvotes": 1
}

And the template image dimensions are:

% identify /tmp/tmemes/templates/2.png 
/tmp/tmemes/templates/2.png PNG 971x544 971x544+0+0 8-bit sRGB 897163B 0.000u 0:00.002
creachadair commented 1 year ago

We figured out what went wrong: A font.Face is not required to be safe for concurrent use, and we were (sometimes) using them concurrently from the cache.

Since the collision would only happen for multiple images that request the same point size, the problem would "disappear" after reloads, since usually someone wins the race and the macro gets regenerated, making it no longer a contender.