Trilium cant be started, complaints about port #3886

Open
opened 2025-10-01 16:34:47 -05:00 by giteasync · 14 comments
Owner

Originally created by @gerroon on GitHub.

I do not remember having this issue before. Apperantly Firefox is using this port so not much I can do about this. Any way to change this?

trilium Generated sourceId=gRy91BDToB3T Port 37840 is already in use

Originally created by @gerroon on GitHub. I do not remember having this issue before. Apperantly Firefox is using this port so not much I can do about this. Any way to change this? `trilium Generated sourceId=gRy91BDToB3T Port 37840 is already in use `
giteasync added the
Difficulty: Easy
label 2025-10-01 16:34:47 -05:00
Author
Owner

@gerroon commented on GitHub:

I actually checked processes and Trilium wsa not running prior to starting it.

@gerroon commented on GitHub: I actually checked processes and Trilium wsa not running prior to starting it.
Author
Owner

@zadam commented on GitHub:

This typically happens when Trilium did not correctly exit and thus still occupies this port - #778

@zadam commented on GitHub: This typically happens when Trilium did not correctly exit and thus still occupies this port - #778
Author
Owner

@zadam commented on GitHub:

Fixed port is used because web clipper needs to find trilium on an expected port. There is no fallback yet since this is the first time this happened (at least as far as I'm aware).

@zadam commented on GitHub: Fixed port is used because web clipper needs to find trilium on an expected port. There is no fallback yet since this is the first time this happened (at least as far as I'm aware).
Author
Owner

@gerroon commented on GitHub:

It was used by Firefox then. Would not it better it sets a random port for that time if there is a port collision?

@gerroon commented on GitHub: It was used by Firefox then. Would not it better it sets a random port for that time if there is a port collision?
Author
Owner

@zadam commented on GitHub:

Well, then that's weird. You can change default port to something else by setting TRILIUM_PORT environment variable.

@zadam commented on GitHub: Well, then that's weird. You can change default port to something else by setting `TRILIUM_PORT` environment variable.
Author
Owner

@ivosm commented on GitHub:

yes, you are completely right. I work in Konsole, so the var was still there but was not visible from the new process. I was so focused on the effect, why it magically started to work but the port wasn't changed. The second part is now clear. :-) Thanks. But the first one ...

@ivosm commented on GitHub: yes, you are completely right. I work in Konsole, so the var was still there but was not visible from the new process. I was so focused on the effect, why it magically started to work but the port wasn't changed. The second part is now clear. :-) Thanks. But the first one ...
Author
Owner

@ivosm commented on GitHub:

problem description

Even more weird experience. (Kubuntu 20.04)
Today after long time everyday use without any change in settings, upgrade etc. T just didn't start. Trying from cmd and got:

DB size: 64188 KB
Note cache load took 100ms
App HTTP server starting up at port 37840
...
Port 37840 is already in use

looking netstat, it isn't used, looking processes nothing connected with T is running
so I set the env var TRILIUM_PORT=37841
start T from cmd and T works as usual
! BUT

DB size: 64188 KB
Note cache load took 100ms
App HTTP server starting up at port 37840
...
Listening on port 37840

and

netstat -lntp |rg 3784
tcp        0      0 0.0.0.0:37840           0.0.0.0:*               NASLOUCHÁ  344311/trilium

So the env var TRILIUM_PORT was not ignored completely but did not change the port.

log

may be glue can be the log (connected from end of yesterday and today)
Today until the setting of TRILIUM_PORT there was only one line for each start but after the setting it was identical with what I could see in console.

23:48:42.105 sync failed: Process exceeded time limit 5000
stack: Error: Process exceeded time limit 5000
    at Object.timeLimit (/usr/lib/trilium/resources/app.asar/src/services/utils.js:257:19)
    at requestToSyncServer (/usr/lib/trilium/resources/app.asar/src/services/setup.js:49:24)
    at Object.hasSyncServerSchemaAndSeed (/usr/lib/trilium/resources/app.asar/src/services/setup.js:12:28)
    at login (/usr/lib/trilium/resources/app.asar/src/services/sync.js:90:29)
    at /usr/lib/trilium/resources/app.asar/src/services/sync.js:35:43
    at Object.doExclusively (/usr/lib/trilium/resources/app.asar/src/services/sync_mutex.js:13:22)
    at async sync (/usr/lib/trilium/resources/app.asar/src/services/sync.js:27:16)


13:30:40.160 DB size: 64188 KB
13:33:08.480 DB size: 64188 KB
13:33:51.082 DB size: 64188 KB
13:39:41.232 DB size: 64188 KB
13:59:53.999 DB size: 64188 KB
13:59:55.450 Note cache load took 93ms
13:59:56.069 App HTTP server starting up at port 37840
13:59:56.069 {
  "appVersion": "0.47.8",
  "dbVersion": 183,
  "syncVersion": 20,
  "buildDate": "2021-10-04T22:18:33+02:00",
  "buildRevision": "1f75b9c92f1f695e4f43230f88d676ab8a0b39c0",
  "dataDirectory": "/home/ismelhaus/.local/share/trilium-data",
  "clipperProtocolVersion": "1.0"
}
13:59:56.069 CPU model: AMD Phenom(tm) II X4 965 Processor, logical cores: 4 freq: 3400 Mhz
13:59:56.074 Listening on port 37840

...

suggestion

  • Would be nice to make the start more failure-resistant, because of 'normal' i.e. GUI type of user is lost in such situation.
  • May be a tiny gui with possibility to go back using the backup could be a life saving feature for that type of users. :-)
@ivosm commented on GitHub: ### problem description Even more weird experience. (Kubuntu 20.04) Today after long time everyday use without any change in settings, upgrade etc. T just didn't start. Trying from cmd and got: ``` DB size: 64188 KB Note cache load took 100ms App HTTP server starting up at port 37840 ... Port 37840 is already in use ``` looking netstat, it isn't used, looking processes nothing connected with T is running so I set the env var `TRILIUM_PORT=37841` start T from cmd and T works as usual ! BUT ``` DB size: 64188 KB Note cache load took 100ms App HTTP server starting up at port 37840 ... Listening on port 37840 ``` and ``` netstat -lntp |rg 3784 tcp 0 0 0.0.0.0:37840 0.0.0.0:* NASLOUCHÁ 344311/trilium ``` So the env var `TRILIUM_PORT` was not ignored completely but did not change the port. ### log may be glue can be the log (connected from end of yesterday and today) Today until the setting of `TRILIUM_PORT` there was only one line for each start but after the setting it was identical with what I could see in console. ``` 23:48:42.105 sync failed: Process exceeded time limit 5000 stack: Error: Process exceeded time limit 5000 at Object.timeLimit (/usr/lib/trilium/resources/app.asar/src/services/utils.js:257:19) at requestToSyncServer (/usr/lib/trilium/resources/app.asar/src/services/setup.js:49:24) at Object.hasSyncServerSchemaAndSeed (/usr/lib/trilium/resources/app.asar/src/services/setup.js:12:28) at login (/usr/lib/trilium/resources/app.asar/src/services/sync.js:90:29) at /usr/lib/trilium/resources/app.asar/src/services/sync.js:35:43 at Object.doExclusively (/usr/lib/trilium/resources/app.asar/src/services/sync_mutex.js:13:22) at async sync (/usr/lib/trilium/resources/app.asar/src/services/sync.js:27:16) 13:30:40.160 DB size: 64188 KB 13:33:08.480 DB size: 64188 KB 13:33:51.082 DB size: 64188 KB 13:39:41.232 DB size: 64188 KB 13:59:53.999 DB size: 64188 KB 13:59:55.450 Note cache load took 93ms 13:59:56.069 App HTTP server starting up at port 37840 13:59:56.069 { "appVersion": "0.47.8", "dbVersion": 183, "syncVersion": 20, "buildDate": "2021-10-04T22:18:33+02:00", "buildRevision": "1f75b9c92f1f695e4f43230f88d676ab8a0b39c0", "dataDirectory": "/home/ismelhaus/.local/share/trilium-data", "clipperProtocolVersion": "1.0" } 13:59:56.069 CPU model: AMD Phenom(tm) II X4 965 Processor, logical cores: 4 freq: 3400 Mhz 13:59:56.074 Listening on port 37840 ... ``` ### suggestion - Would be nice to make the start more failure-resistant, because of 'normal' i.e. GUI type of user is lost in such situation. - May be a tiny gui with possibility to go back using the backup could be a life saving feature for that type of users. :-)
Author
Owner

@abitofevrything commented on GitHub:

In Linux, if you want the variable to last more than a single command (i.e one line), you need to use the export directive, like export TRILIUM_PORT=.... Otherwise the variable will be forgotten after the line finishes executing.

@abitofevrything commented on GitHub: In Linux, if you want the variable to last more than a single command (i.e one line), you need to use the `export` directive, like `export TRILIUM_PORT=...`. Otherwise the variable will be forgotten after the line finishes executing.
Author
Owner

@zadam commented on GitHub:

Hi,

netstat -lntp |rg 3784
tcp 0 0 0.0.0.0:37840 0.0.0.0:* NASLOUCHÁ 344311/trilium
So the env var TRILIUM_PORT was not ignored completely but did not change the port.

the port is the same, it looks like the env variable was ignored - how did you set it? In Linux you can run it like:

TRILIUM_PORT=12345 ./trilium

@zadam commented on GitHub: Hi, > netstat -lntp |rg 3784 > tcp 0 0 0.0.0.0:37840 0.0.0.0:* NASLOUCHÁ 344311/trilium > So the env var TRILIUM_PORT was not ignored completely but did not change the port. the port is the same, it looks like the env variable was ignored - how did you set it? In Linux you can run it like: > TRILIUM_PORT=12345 ./trilium
Author
Owner

@ivosm commented on GitHub:

sorry, I wasn't completely precise and slightly kidding.
The meaning of "TRILIUM_PORT was not ignored completely" was, that it just did the magick and T started but what was expected, the changed port didn't work at all.
Yes, there is a difference between the case when TRILIUM_PORT is set on the same line or not. If this is on the same line, it works. If it isn't, it doesn't work.
The weird behavior is, that after setting this var, it magically started to work. Why, if T ignored it (it kept the default port 37840).
I was all the time keeping in mind, that the main point is to not being able to start T and the "story" with port as a possible glue.

@ivosm commented on GitHub: sorry, I wasn't completely precise and slightly kidding. The meaning of "TRILIUM_PORT was not ignored completely" was, that it just did the magick and T started but what was expected, the changed port didn't work at all. Yes, there is a difference between the case when `TRILIUM_PORT` is set on the same line or not. If this is on the same line, it works. If it isn't, it doesn't work. The weird behavior is, that after setting this var, it magically started to work. Why, if T ignored it (it kept the default port 37840). I was all the time keeping in mind, that the main point is to not being able to start T and the "story" with port as a possible glue.
Author
Owner

@ivosm commented on GitHub:

Today the same problem occurred.

  • T can't start and blames, that port 37840 is in use
  • T can start on any other port without problem
  • netstat -lntp shows nothing BUT netstat shows 37840 as connected
  • the connection is from T addon in FF
  • Close FF, wait a moment (port get from connected to time-wait first and then release completely) and T works as usual on 37840
    Result: T is right, the port is really in use. FF addon is the cause.
@ivosm commented on GitHub: Today the same problem occurred. - T can't start and blames, that port 37840 is in use - T can start on any other port without problem - `netstat -lntp` shows nothing BUT `netstat` shows 37840 as `connected` - the connection is from T addon in FF - Close FF, wait a moment (port get from connected to time-wait first and then release completely) and T works as usual on 37840 Result: T is right, the port is really in use. FF addon is the cause.
Author
Owner

@zadam commented on GitHub:

FF addon is the cause.

FF addon connects to the port as a client, in that sense it can't block it (at least AFAIK).

@zadam commented on GitHub: > FF addon is the cause. FF addon connects to the port as a client, in that sense it can't block it (at least AFAIK).
Author
Owner

@FliegendeWurst commented on GitHub:

I just had this issue, and it was caused by Thunderbird (lsof output):

.thunderb 4636                            arne  156u     IPv6              30797       0t0        TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED)
.thunderb 4636 4641 IPC\x20I/             arne  156u     IPv6              30797       0t0        TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED)
.thunderb 4636 4647 Netlink               arne  156u     IPv6              30797       0t0        TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED)
.thunderb 4636 4648 Socket                arne  156u     IPv6              30797       0t0        TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED)
.thunderb 4636 4649 IPDL\x20B             arne  156u     IPv6              30797       0t0        TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED)
.thunderb 4636 4651 gmain                 arne  156u     IPv6              30797       0t0        TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED)
.thunderb 4636 4653 JS\x20Wat             arne  156u     IPv6              30797       0t0        TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED)
.thunderb 4636 4655 Timer                 arne  156u     IPv6              30797       0t0        TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED)
.thunderb 4636 4656 Cache2                arne  156u     IPv6              30797       0t0        TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED)
@FliegendeWurst commented on GitHub: I just had this issue, and it was caused by Thunderbird (`lsof` output): ``` .thunderb 4636 arne 156u IPv6 30797 0t0 TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED) .thunderb 4636 4641 IPC\x20I/ arne 156u IPv6 30797 0t0 TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED) .thunderb 4636 4647 Netlink arne 156u IPv6 30797 0t0 TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED) .thunderb 4636 4648 Socket arne 156u IPv6 30797 0t0 TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED) .thunderb 4636 4649 IPDL\x20B arne 156u IPv6 30797 0t0 TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED) .thunderb 4636 4651 gmain arne 156u IPv6 30797 0t0 TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED) .thunderb 4636 4653 JS\x20Wat arne 156u IPv6 30797 0t0 TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED) .thunderb 4636 4655 Timer arne 156u IPv6 30797 0t0 TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED) .thunderb 4636 4656 Cache2 arne 156u IPv6 30797 0t0 TCP nixOS:37840->imap.kit.edu:imaps (ESTABLISHED) ```
Author
Owner

@dosubot[bot] commented on GitHub:

This is a known issue: Thunderbird (and Firefox) can use port 37840 as an ephemeral local port for outgoing connections, which blocks Trilium from binding to it as a server. This happens because Linux assigns ephemeral ports in the 32768–60999 range, and Trilium’s default port falls within that range. If Thunderbird grabs 37840 before Trilium starts, Trilium will fail with a "port already in use" error—even though no other Trilium process is running. Closing Thunderbird (or whichever app is using the port) will release it and let Trilium start normally. You can also work around this by setting a different port for Trilium using the TRILIUM_PORT environment variable or editing config.ini, but note that the web clipper expects the default port, so changing it may affect that feature. More details and discussion are in this thread and here.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub: <!-- Answer --> This is a known issue: Thunderbird (and Firefox) can use port 37840 as an ephemeral local port for outgoing connections, which blocks Trilium from binding to it as a server. This happens because Linux assigns ephemeral ports in the 32768–60999 range, and Trilium’s default port falls within that range. If Thunderbird grabs 37840 before Trilium starts, Trilium will fail with a "port already in use" error—even though no other Trilium process is running. Closing Thunderbird (or whichever app is using the port) will release it and let Trilium start normally. You can also work around this by setting a different port for Trilium using the `TRILIUM_PORT` environment variable or editing `config.ini`, but note that the web clipper expects the default port, so changing it may affect that feature. More details and discussion are in [this thread](https://github.com/TriliumNext/Trilium/issues/3651) and [here](https://github.com/TriliumNext/Trilium/issues/821). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/750deb9b-c26b-49bc-8cc4-d31906a47862?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/750deb9b-c26b-49bc-8cc4-d31906a47862?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/750deb9b-c26b-49bc-8cc4-d31906a47862?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/750deb9b-c26b-49bc-8cc4-d31906a47862?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/750deb9b-c26b-49bc-8cc4-d31906a47862?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/750deb9b-c26b-49bc-8cc4-d31906a47862?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/750deb9b-c26b-49bc-8cc4-d31906a47862?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/4af773a7-9840-4978-96dc-c436f6f437cf/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/TriliumNext/Trilium/issues/821)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TriliumNext/Trilium#3886
No description provided.