Score:7

How launch Firefox snap with profile that is already running

cn flag

Firefox is broken on a fresh install of Ubuntu 22.04 LTS (Xubuntu) with Firefox 113.0.2, installed by the now default method, from Snap.

When I try to launch Firefox with a profile that is already running, I get an error:

"Firefox is already running, but is not responding. To use Firefox, you must first close the existing Firefox process, restart your device, or use a different profile."

This problem did not exist with Ubuntu 20.04 (where the default install was managed via apt).

Using Firefox on 20.04, my everyday workflow as a knowledge worker involved starting new instances of Firefox with profiles that were already running on other workspaces.

Now when I run Firefox from the terminal I get the following error:

._. firefox -P default "https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1951491"
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.

Numerous other reports on the matter suggest that the problem can sometimes be that the environment variable $DBUS_SESSION_BUS_ADDRESS is not set, and that the fix can involve simply setting this envar to unix:path=/run/user/$DBUS_SESSION_BUS_ADDRESS/bus. For example, see here, here and here.

My $DBUS_SESSION_BUS_ADDRESS does appear to be set.

._. echo $DBUS_SESSION_BUS_ADDRESS
unix:path=/run/user/1000/bus

._. echo $XDG_RUNTIME_DIR
/run/user/1000

But systemd thinks it is not.

._. sudo systemd --user
Trying to run as user instance, but $XDG_RUNTIME_DIR is not set.

Reports on this problem suggest systemd might be responsible.

But syslog seems to report no problems when Firefox is called. It runs with uid 1000.

When I run SNAPD_DEBUG=1 snap run firefox --profile-manager, Snap also reports that it is using a uid of 1000 but does appear to be have an error:

ATTENTION: default value of option mesa_glthread overridden by environment.

What can I do to get Firefox working properly from its default Snap install on Ubuntu 22.04 LTS, and launch new windows/instances with profiles that are already running?

I cannot simply close the other running window/instance of Firefox, since that would destroy my workflow. Indeed, I usually have multiple windows open with the same profile on multiple workspaces.

To close the other instance would defeat the object of my attempt to launch Firefox with a profile that is already open.(Thanks to @raffa for the suggestion).

Whether my prior habit of launching Firefox multiple times with profiles that were already running did so in a new window in the same running instance or a new window and new instance makes no difference to me: it worked before; now it does not.

Esther avatar
es flag
the mesa_glthread message does not prevent Firefox from working; I have a whole bunch of those each time I run Firefox and it works fine. Also notice it's not an error, just a message ("Attention")
Score:4
jp flag
sudo systemd --user

Is invoked as the user root(not your current user invoking sudo) without actual root login and therefore, invoked as such, doesn't have an existing user-runtime environment including a runtime-directory ... Therefore, the error you see i.e.:

Trying to run as user instance, but $XDG_RUNTIME_DIR is not set.

Is totally normal and doesn't reflect on your current running invoking user ... What reflects the current state of your current running invoking user, although IMO a strange and a bad idea for just testing the availability of a user runtime-directory (Be prepared to reboot your system or don't try this as your system will become unstable), is:

systemd --user

Which should initiate fine in your case ruling out your concern about the availability of a user runtime-directory or runtime-environment.

Please, see this related answer for more info.

That said, the message you see i.e.:

"Firefox is already running, but is not responding. To use Firefox, you must first close the existing Firefox process, restart your device, or use a different profile."

Is actually what it means and should be solved as it suggests ... Not limited to Firefox, system and user services take time to exit if they respond and quickly/immediately trying to start another instance might result in such error ... With SNAP installed applications, it's even more complicated in that sense.

What you can do otherwise is to forcefully kill all running Firefox process with e.g.:

pkill -9 firefox

If your SNAP firefox installation is okay, then that should allow you to start a new Firefox instance instantly or otherwise look into fixing your SNAP Firefox installation.

What can I do to get Firefox working properly from its default Snap install on Ubuntu 22.04 LTS, and launch new instances with profiles that are already running?

AFAIK, unfortunately, nothing ... A Firefox profile is locked(Two files lock(symlink) and .parentlock will be placed in the profile's directory for this purpose) when in use by a Firefox process in favor of this process so no other Firefox process can use it to avoid inevitable profile data corruption ... There is no easy(or otherwise) way around that ... Mozilla rules ... Those lock files as can be seen on Mozilla support are a culprit and will prevent a new Firefox instance from running with a profile that has them in its main directory even if they were just left there after a Firefox ungraceful shutdown incident and even if that profile is moved to another machine ... Please, see for example:

There is, however, a slight chance that I misunderstood your requirements and the fact that SNAP applications are indeed different from DEB packages installed through APT in that they run in an isolated(sandboxed) environment which actually alters permissions and changes scopes for their processes ... Depending on whether or not this might be the culprit, there are a couple try-worthy instance and profile related flags ... In particular, the -new-instance and -no-remote flags ... Please, see if they(or others) can help and refer to:

markling avatar
cn flag
I neglected to state that closing any existing running instances is not an option. I'll update my answer. The info you provide here is most instructive. Thank you.
Raffa avatar
jp flag
@markling I updated the answer for that ... I wish it were good news, but ... :-) ... Your best bet, as I see it, is using a different profile for each new instance you wish to run.
markling avatar
cn flag
What you say about it not being possible, @Raffa, seems odd, because doing that has been an essential part of my daily workflow as a knowledge user for the last couple of years, using the apt version of Firefox.
Raffa avatar
jp flag
@markling I believe you but don't know how ... There, might be a way that I don't know of or you might mean opening new tabs in the same main window running under one main process per profile which if you mean this, then yes, Firefox will do this automatically regardless of source installed from SNAP or APT and your command should actually open in a new tab by default unless you changed something or you are running mixed Firefox versions or you are running Firefox in the background or the with `--headless` option as any of the latter cases will be considered as a separate process.
Raffa avatar
jp flag
@markling Or of course if there is an unresponsive Firefox process in the background that is using a certain profile ... Kindly see what Mozilla support pages say about profile locking ... e.g. https://support.mozilla.org/en-US/kb/firefox-already-running-not-responding and https://support.mozilla.org/en-US/questions/1203397#:~:text=%22LOCK%22%20file.-,The%20'''parent.,Delete%20that%20'''parent.
Raffa avatar
jp flag
@markling Also tabs or windows are just a concept as it could as well indeed be opening in a new window ... Those however need to be run under the main process locking the profile ... There could be many windows for the same profile under a single main process but not more than one main process holding and locking the profile ... My perspective is purely system/user processes level and not windows/tabs ... Technically if a profile is locked by a process whether responsive or otherwise GUI or headless, that profile is not usable by another Firefox process as per Mozilla.
markling avatar
cn flag
your suggestion that I may have been opening Firefox in the same instance, and same window when I thought I was opening a new window/instance is unapt. The question is clear: I have been opening new instances of Firefox with a profile that is already running on another workspace. The new instance opens in the current workspace in a new window. Subsequent calls to Firefox from that workspace then open in that same window. Now, it might be the same instance. That is true. But it is a new window on a new workspace with a profile that is already running elsewhere.
Raffa avatar
jp flag
@markling As it appears as long as those lock files are present in the profile directory, no other process can use it even if they were just left there by previews ungraceful Firefox shutdown or even moved to another machine as discussed in the Mozilla support posts linked above ... There is, however, a possibility that the process tree and management could be slightly different with APT version and new instances were more flexibly accepted as child processes but this is merely a guess on my side and I don't know this for a fact.
markling avatar
cn flag
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/146402/discussion-between-markling-and-raffa).
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.