tmux leaks memory in pane-border-status

Bug #1766942 reported by antgel
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
tmux (Ubuntu)
Fix Released
Undecided
Unassigned
Bionic
Fix Released
Undecided
Karl Stenerud

Bug Description

[Impact]

A memory leak in tmux causes it to eventually fail when run for long periods of time. Since long term tmux sessions are common, this becomes a real problem for sysadmins, etc.

[Test Case]

# apt update
# apt dist-upgrade -y
# apt install -y tmux
# tmux -L none -f /dev/null new-session -s leaky-tmux-test 'tmux set-option -w -g pane-border-status top; tmux pipe-pane "cat>/tmp/leaky-tmux-test.log"; p=${TMUX#*,}; p=${p%,*}; s=0; j=0; echo "ITER: RSZ"; while [ $j -lt 6000 ] ; do j=$((j+1)); n=$(ps hwo rsz $p); printf "\e]2;%d: %d\e\\\\\r%4d: %d" $j $n $j $n; [ $s -ne $n ] && { echo; s=$n; }; done'
[exited]
# cat /tmp/leaky-tmux-test.log ; echo
ITER: RSZ
   1: 3712
1360: 3776
2725: 3904
4215: 4032
5743: 4160
6000: 4160 (example output)

RSZ will only change during the test if there's a memory leak. By comparison, we get correct behavior running without pane-border-status top:

$ tmux -L none -f /dev/null new-session -s leaky-tmux-test 'tmux pipe-pane "cat>/tmp/leaky-tmux-test.log"; p=${TMUX#*,}; p=${p%,*}; s=0; j=0; echo "ITER: RSZ"; while [ $j -lt 6000 ] ; do j=$((j+1)); n=$(ps hwo rsz $p); printf "\e]2;%d: %d\e\\\\\r%4d: %d" $j $n $j $n; [ $s -ne $n ] && { echo; s=$n; }; done'
[exited]
$ cat /tmp/leaky-tmux-test.log ; echo
ITER: RSZ
   1: 3492
6000: 3492

[Regression Potential]

Since this is only plugging a memory leak, no other behavior should be affected.

[Original Description]

The upstream bug is reported and fixed at https://github.com/tmux/tmux/issues/1167.

Can we either patch the package (patch at https://github.com/tmux/tmux/commit/c363c236aaea5b7a879493d8f3c85bead546f063) or upgrade to 2.7 (I guess this is less likely to happen given the imminent release).

Related branches

Changed in tmux (Ubuntu):
status: New → Fix Released
tags: added: server-next
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Hi antgel,
I'm passing a few bugs with not enough attention atm.
Your report is great - I put it in a queue to hopefully be picked up soon.

Do you have a testcase other than waiting to see the issue?
It is in screen_redraw_make_pane_status so maybe there is something that forces the redraw one could loop on?

I tried
  $ while /bin/true; do tmux refresh-client; done
but that did not expose the issue.

Changed in tmux (Ubuntu Bionic):
status: New → Confirmed
Revision history for this message
Karl Stenerud (kstenerud) wrote :

Confirmed the behavior with the following test from https://github.com/tmux/tmux/issues/1167#issuecomment-349040998

Run a simple/crude test in order to verify this finding:

$ tmux -L none -f /dev/null new-session -s leaky-tmux-test 'tmux set-option -w -g pane-border-status top; tmux pipe-pane "cat>/tmp/leaky-tmux-test.log"; p=${TMUX#*,}; p=${p%,*}; s=0; j=0; echo "ITER: RSZ"; while [ $j -lt 6000 ] ; do j=$((j+1)); n=$(ps hwo rsz $p); printf "\e]2;%d: %d\e\\\\\r%4d: %d" $j $n $j $n; [ $s -ne $n ] && { echo; s=$n; }; done'
[exited]
$ cat /tmp/leaky-tmux-test.log ; echo
ITER: RSZ
   1: 3512
1993: 3568
3650: 3696
5279: 3824
6000: 3824

To compare, run it without tmux set-option -w -g pane-border-status top:

$ tmux -L none -f /dev/null new-session -s leaky-tmux-test 'tmux pipe-pane "cat>/tmp/leaky-tmux-test.log"; p=${TMUX#*,}; p=${p%,*}; s=0; j=0; echo "ITER: RSZ"; while [ $j -lt 6000 ] ; do j=$((j+1)); n=$(ps hwo rsz $p); printf "\e]2;%d: %d\e\\\\\r%4d: %d" $j $n $j $n; [ $s -ne $n ] && { echo; s=$n; }; done'
[exited]
$ cat /tmp/leaky-tmux-test.log ; echo
ITER: RSZ
   1: 3492
6000: 3492

-------------

Tested this with tmux 2.7 (in cosmic) and verified it fixed. Bionic is still affected.

Changed in tmux (Ubuntu Bionic):
assignee: nobody → Karl Stenerud (kstenerud)
Changed in tmux (Ubuntu Bionic):
status: Confirmed → In Progress
description: updated
Revision history for this message
Brian Murray (brian-murray) wrote : Please test proposed package

Hello antgel, or anyone else affected,

Accepted tmux into bionic-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/tmux/2.6-3ubuntu0.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-bionic to verification-done-bionic. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-bionic. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in tmux (Ubuntu Bionic):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-bionic
Revision history for this message
Karl Stenerud (kstenerud) wrote :
tags: added: verification-done verification-done-bionic
removed: verification-needed verification-needed-bionic
Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Which package version has been used for verification? Please note that this information is required (as seen in #3 ).

Changed in tmux (Ubuntu Bionic):
status: Fix Committed → Incomplete
Revision history for this message
Brian Murray (brian-murray) wrote :

I went ahead and tested this myself using the version of the package from bionic-proposed.

root@tester:~# tmux -L none -f /dev/null new-session -s leaky-tmux-test 'tmux set-option -w -g pane-border-status top; tmux pipe-pane "cat>/tmp/leaky-tmux-test.log"; p=${TMUX#*,}; p=${p%,*}; s=0; j=0; echo "ITER: RSZ"; while [ $j -lt 6000 ] ; do j=$((j+1)); n=$(ps hwo rsz $p); printf "\e]2;%d: %d\e\\\\\r%4d: %d" $j $n $j $n; [ $s -ne $n ] && { echo; s=$n; }; done'
[exited]
root@tester:~# root@tester:~# cat /tmp/leaky-tmux-test.log ITER: RSZ
   1: 2796
6000: 2796root@tester:~# apt-cache policy tmux
tmux:
  Installed: 2.6-3ubuntu0.1
  Candidate: 2.6-3ubuntu0.1
  Version table:
 *** 2.6-3ubuntu0.1 500
        500 http://192.168.10.7/ubuntu bionic-proposed/main amd64 Packages
        100 /var/lib/dpkg/status
     2.6-3 500
        500 http://192.168.10.7/ubuntu bionic/main amd64 Packages

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package tmux - 2.6-3ubuntu0.1

---------------
tmux (2.6-3ubuntu0.1) bionic; urgency=medium

  * d/p/tmux-pane-border-status-leak.patch: Fixed memory leak in
    screen_redraw_make_pane_status (upstream fix). (LP: #1766942)

 -- Karl Stenerud <email address hidden> Mon, 29 Oct 2018 19:33:11 +0100

Changed in tmux (Ubuntu Bionic):
status: Incomplete → Fix Released
Revision history for this message
Brian Murray (brian-murray) wrote : Update Released

The verification of the Stable Release Update for tmux has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.