Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting a "failed to connect to server" message from tmux when I try to list sessions?

Here's what's happening to me: I start tmux sessions using tmux -L name1, tmux -L name2; then I detatch them using ctrl+B+d. Then I try to get a list of the currently running sessions on my computer. However, when I run tmux ls, I get an error message:

failed to connect to server: Connection refused 

Is this a bug? I'm familiar with screen; I regard screen -ls as a very useful function since I might start a session and leave it running for weeks before the next time I attach to it. Because of this, the ability to list current running tmux sessions is quite important for me. Why does tmux ls return a "connection refused" error when I know tmux is running?

like image 806
thinke365 Avatar asked Mar 12 '12 14:03

thinke365


People also ask

How do I get out of tmux session without killing it?

Then type "exit" or Ctrl-d. Note that there is no need for Ctrl-b in this step. Once you type "exit" or Ctrl-d in the last remaining pane, tmux will close. You can also exit tmux by pressing : to go to the bottom bar of the tmux window.

What is tmux server?

tmux is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached. When tmux is started it creates a new session with a single window and displays it on screen.

How do I enable tmux in terminal?

Press Ctrl+B, and then Q to make tmux briefly flash the number of each pane. These numbers are used in prompts and messages from tmux . Press Ctrl+B, and then X to close the current pane.


1 Answers

TL;DR: Try sending SIGUSR1 signal to the tmux server process.

In my case, after about 8 days of inactivity, I was not able to reattach:

$ tmux attach no sessions 

However, a grep for tmux process got me this output:

$ ps -aef | fgrep -i tmux hari     7139     1  1  2016 ?        2-20:32:31 tmux hari    25943 25113  0 22:00 pts/0    00:00:00 fgrep --color=auto -i tmux 

As suggested by @7heo.tk, this indicates that tmux server is still running, but tmux ls was giving failed to connect to server: Connection refused error. I verified that the tmp directory that belonged to the tmux session existed and lsof -p 7139 (the pid of tmux server) showed that the socket file is open:

COMMAND  PID  USER   FD   TYPE             DEVICE SIZE/OFF       NODE NAME tmux    7139 hari    5u  unix 0x0000000000000000      0t0 1712879255 /tmp/tmux-50440/default 

I also tried explicitly specifying the -S /tmp/tmux-50440/default to tmux but it didn't help. However, I read in the tmux man page that sending SIGUSR1 would make tmux recreate the socket file, so I tried that and I was able to immediately find the session and reattach:

$ kill -s USR1 7139 $ tmux ls 0: 12 windows (created Mon Apr 18 21:17:55 2016) [198x62] 
like image 136
haridsv Avatar answered Sep 20 '22 23:09

haridsv