Volume XXII, number 280Wednesday, October 7, 2026Latest message 1 hour ago

The Git List

News and archive of git@vger.kernel.org, since April 2005

gitk: race condition when changing view

2 messages between Apr 16, 2026 and Apr 18, 2026, from Michael Warmuth-Uhl, Johannes Sixt.

Plain Markdown or JSON for tools and agents.

Michael Warmuth-UhlApr 16, 2026, 21:36 UTC on lore
Hi.
when displaying a bigger commit and then changing the view, gitk reports 
        can't read "treediffs(b107a60c5bed3002ecef93b4405a44d809776e6f)": no such variable
        can't read "treediffs(b107a60c5bed3002ecef93b4405a44d809776e6f)": no such variable
            while executing
        "lsearch -exact $treediffs($ids) $fname"
            (procedure "makediffhdr" line 7)
            invoked from within
        "makediffhdr $fname $ids"
            (procedure "parseblobdiffline" line 56)
            invoked from within
        "parseblobdiffline $ids $line"
            (procedure "getblobdiffline" line 16)
            invoked from within
        "getblobdiffline file6 b107a60c5bed3002ecef93b4405a44d809776e6f"
            ("eval" body line 1)
            invoked from within
        "eval $script"
            (procedure "dorunq" line 11)
            invoked from within
        "dorunq"
            ("after" script)
It is reproducible with:
        TCDIR=/tmp/testcase
        N=512
        rm -rf $TCDIR
        git init $TCDIR
        for i in `seq $N` ; do 
            dd if=/dev/random status=none bs=1024 count=16 | uuencode "" > $TCDIR/foo_$i 
        done
        git -C $TCDIR add . 
        git -C $TCDIR commit -m "commit" 
        cd $TCDIR
        gitk --all
followed by an immediate change to "All Files" in gitk menu "View".

That happens because proc showview (and some others) clear treediffs which is still needed by tasks pending in runq.

The patch below makes showview wait until runq is empty which is slow (waits for useless operations) and feels wrong. I have no idea how to cleanly flush runq instead.

The same issue has been mentioned here before: 
	https://stackoverflow.com/questions/17977996/gitk-cant-read-treediffs-error
Michael
---
diff --git a/gitk-git/gitk b/gitk-git/gitk
index 2730274966..f40bb1aa8c 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -281,10 +281,11 @@ proc gitworktree {} {
 # run before X event handlers, so reading from a fast source can
 # make the GUI completely unresponsive.
 proc run args {
-    global isonrunq runq currunq
+    global isonrunq runq currunq runq_active
 
     set script $args
     if {[info exists isonrunq($script)]} return
+    set $runq_active 1
     if {$runq eq {} && ![info exists currunq]} {
         after idle dorunq
     }
@@ -297,8 +298,9 @@ proc filerun {fd script} {
 }
 
 proc filereadable {fd script} {
-    global runq currunq
+    global runq currunq runq_active
 
+    set $runq_active 1
     fileevent $fd readable {}
     if {$runq eq {} && ![info exists currunq]} {
         after idle dorunq
@@ -318,12 +320,20 @@ proc nukefile {fd} {
     }
 }
 
+proc wait_runq_empty {} {
+    global runq runq_active
+    while {$runq ne {} || $runq_active > 0} {
+        dorunq
+    }
+}
+
 proc dorunq {} {
-    global isonrunq runq currunq
+    global isonrunq runq currunq runq_active
 
     set tstart [clock clicks -milliseconds]
     set t0 $tstart
     while {[llength $runq] > 0} {
+        set $runq_active 1
         set fd [lindex $runq 0 0]
         set script [lindex $runq 0 1]
         set currunq [lindex $runq 0]
@@ -343,6 +353,7 @@ proc dorunq {} {
         } elseif {$fd eq {}} {
             unset isonrunq($script)
         }
+        set $runq_active 0
         set t0 $t1
         if {$t1 - $tstart >= 80} break
     }
@@ -825,6 +836,7 @@ proc reloadcommits {} {
     global showneartags treediffs commitinterest cached_commitrow
     global targetid commitinfo
 
+    wait_runq_empty
     set selid {}
     if {$selectedline ne {}} {
         set selid $currentid
@@ -3660,6 +3672,7 @@ proc pop_flist_menu {w X Y x y} {
     global ctext cflist cmitmode flist_menu flist_menu_file
     global treediffs diffids
 
+    wait_runq_empty
     stopfinding
     set l [lindex [split [$w index "@$x,$y"] "."] 0]
     if {$l <= 1} return
@@ -4664,6 +4677,8 @@ proc showview {n} {
     global hlview selectedhlview commitinterest
 
     if {$n == $curview} return
+
+    wait_runq_empty
     set selid {}
     set ymax [lindex [$canv cget -scrollregion] 3]
     set span [$canv yview]
@@ -12909,6 +12924,7 @@ if {[file exists $themeloader]} {
 set appname "gitk"
 
 set runq {}
+set runq_active 0
 set history {}
 set historyindex 0
 set fh_serial 0
Johannes SixtApr 18, 2026, 17:48 UTC in reply to Michael Warmuth-Uhl on lore

Re: gitk: race condition when changing view

Am 16.04.26 um 23:36 schrieb Michael Warmuth-Uhl:
Show 52 quoted lines
> when displaying a bigger commit and then changing the view, gitk reports 
> 
>         can't read "treediffs(b107a60c5bed3002ecef93b4405a44d809776e6f)": no such variable
>         can't read "treediffs(b107a60c5bed3002ecef93b4405a44d809776e6f)": no such variable
>             while executing
>         "lsearch -exact $treediffs($ids) $fname"
>             (procedure "makediffhdr" line 7)
>             invoked from within
>         "makediffhdr $fname $ids"
>             (procedure "parseblobdiffline" line 56)
>             invoked from within
>         "parseblobdiffline $ids $line"
>             (procedure "getblobdiffline" line 16)
>             invoked from within
>         "getblobdiffline file6 b107a60c5bed3002ecef93b4405a44d809776e6f"
>             ("eval" body line 1)
>             invoked from within
>         "eval $script"
>             (procedure "dorunq" line 11)
>             invoked from within
>         "dorunq"
>             ("after" script)
> 
> It is reproducible with:
> 
>         TCDIR=/tmp/testcase
>         N=512
> 
>         rm -rf $TCDIR
>         git init $TCDIR
>         for i in `seq $N` ; do 
>             dd if=/dev/random status=none bs=1024 count=16 | uuencode "" > $TCDIR/foo_$i 
>         done
>         git -C $TCDIR add . 
>         git -C $TCDIR commit -m "commit" 
> 
>         cd $TCDIR
>         gitk --all
> 
> followed by an immediate change to "All Files" in gitk menu "View".
> 
> That happens because proc showview (and some others) clear treediffs which is 
> still needed by tasks pending in runq.
> 
> The patch below makes showview wait until runq is empty which is slow (waits for 
> useless operations) and feels wrong. I have no idea how to cleanly flush runq 
> instead.
> 
> The same issue has been mentioned here before: 
> 	https://stackoverflow.com/questions/17977996/gitk-cant-read-treediffs-error
> 
> Michael
Thank you for the report, the reproducer, and for digging into the issue.

Waiting for the process to complete is certainly not the most desirable way to handle the situation. I've attempted to clear the run queue with the patch below, but the reproduction recipe still triggers an error 'can't unset "currunq": no such variable', the reason being that proc dorunq is entered recursively via one of the queued scripts, and I haven't found why that is the case.

I'll look into this further as time permits, but don't hold your breath.
-- Hannes
diff --git a/gitk b/gitk
index dc042a5..51d9fe5 100755
--- a/gitk
+++ b/gitk
@@ -4693,6 +4693,17 @@ proc showview {n} {
     }
     unselectline
     normalline
+    global runq
+    foreach curq $runq {
+        set fd [lindex $curq 0]
+        if {$fd ne {}} {
+            catch {close $fd}
+        } else {
+            set script [lindex $curq 1]
+            unset isonrunq($script)
+        }
+    }
+    set runq {}
     unset -nocomplain treediffs
     clear_display
     if {[info exists hlview] && $hlview == $n} {

Back to recent threads

gitk: race condition when changing view | The Git List