martenlienen/pelican-katex

Error on build: permission denied

Closed this issue · 8 comments

First of all, thanks for implementing KaTex for markdown too :)

When executing my pelican build script, the following error occurs:

events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: listen EACCES: permission denied C:\Users\User\AppData\Local\Temp\pelican_katexrlj4qnm4\katex.sock
    at Server.setupListenHandle [as _listen2] (net.js:1262:19)
    at listenInCluster (net.js:1327:12)
    at Server.listen (net.js:1425:5)
    at Object.<anonymous> (a:\workspace\[PathHiddenOnGithub]\.venv\lib\site-packages\pelican_katex\render-katex.js:34:8)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
Emitted 'error' event at:
    at emitErrorNT (net.js:1306:8)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
ERROR: Could not process .\test.md
  | KaTeXError: KaTeX server did not start up after 1.0 seconds. Consider increasing KATEX_STARTUP_TIMEOUT.

It seems that the running process cannot access the temporary path. The directory that should contain katex.sock is just empty. Running the build script with admin rights doesn't help.

  • Windows 10 64 bit
  • Python 3.7.4
  • Nodejs v10.16.3
  • Relevant packages:
    • pelican: 4.2.0
    • pelican-katex: 1.3.0

Unfortunately, I don't have access to Windows to reproduce the error. Did you experience the problem with earlier versions of pelican-katex? Because there were no changes to the relevant code besides moving it to a different file. Can you check the permissions on the temporary directory (C:\Users\User\AppData\Local\Temp\pelican_katexrlj4qnm4 in this case)?

I didn't use earlier versions as I don't use rst files. I've tried to use the plugin a few months ago because I didn't realize it wasn't supporting markdown at that time. Building the page worked back then but I had no rst files, so the issue was probably already there but unnoticed.

The problem is most likely related to the permissions of the temp directory, the whole temp folder is write protected by default. Although it is a little bit strange that Python fails to write to the pelican_katex subfolder as it is the creator of that sub-folder. I unfortunately don't know much about file permissions. The Python documentation on mkdtemp()(used here) says:

The directory is readable, writable, and searchable only by the creating user ID.

Is there any way for you to find out what is going on exactly and propose a fix? As I said, unfortunately I don't have access to a Windows system and I could not find any information regarding this behavior and mkdtemp on the internet to guess a fix.

I will try it :)

Ok, so I think I found the issue.

Its probably not permission related. First, I tried to manually give full permissions to everybody to the file with icacls (like chmod on Unix systems) - that didn't help at all.
Then it looked like node needs administrator permissions - that also wasn't the issue.

Instead, it is the server. If you have a look at the documentation on server.listen(), there are multiple overloaded function calls possible. I'm not sure weather we are using the first one - handle can be a file object - or the third one (IPC).

  • If the first one is used:
    Unfortunately, the documentation says:

    Listening on a file descriptor is not supported on Windows.

    If that's the case, we need to find another way to run the server. I don't now much about that, so unfortunately I'm not really able to help here.

  • If the IPC variant is used:
    The documentation on this states that Windows paths need special treatment, \\?\pipe\ must precede the actual socket path. I've tried this but it didn't work. The the error was gone but the server didn't start. I got just the timeout message (probably because we're not using IPC. I really don't know what that is).

I really would have liked to fix this and open a PR, but I think i'm not able to solve this as I have almost no knowledge on that area and I'm very limited in time at the moment. If you have any other ideas, I would really appreciate that :)

We are using the IPC variant and that looks like the problem. An alternative I see is to use a network socket instead when the host OS is windows. That should work on all OSs though I won't be able to do that before Thursday and likely not until Friday. I will notify you here when I have a version ready for you to try :)

That sounds great, thank you very much :)

I have added a way to replace unix socket IPC with a network connection. Can you try it? The code is in pull request #3.