Tk Source Code

View Ticket
Login
Ticket UUID: bf65b83d43775bc7a3dbbba8c154752157d1e0fb
Title: Tk crash: XIO: fatal IO error 88 (Socket operation on non-socket)
Type: Bug Version: 8.6.12
Submitter: sbron Created on: 2021-11-20 12:37:43
Subsystem: 67. Unix Window Operations Assigned To: nobody
Priority: 5 Medium Severity: Severe
Status: Open Last Modified: 2026-09-23 20:41:21
Resolution: None Closed By: nobody
    Closed on:
Description:

Tk crashes when a display that has been used in the past goes away, even if there are no longer any widgets on the display. With different scripts I saw either:

XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":1"
      after 125 requests (125 known processed) with 0 events remaining.
or
XIO:  fatal IO error 88 (Socket operation on non-socket) on X server ":1"
      after 62 requests (62 known processed) with 0 events remaining.

The problem was found while trying to use CloudTk to provide a window on a new virtual desktop whenever a web browser connected to the application.

Tk: 8.6.12 OS: openSUSE Leap 15.2

Below a small script to reproduce the problem:

proc sleep {ms} {
    after $ms [list [info coroutine]]
    yield
}

proc main {argv} {
    package require Tk
    sleep 1000
    puts "Starting Xvnc"
    set pid [exec Xvnc :1 2>/dev/null &]
    sleep 1000
    puts "Creating toplevel on :1"
    toplevel .t1 -screen :1
    sleep 1000
    puts "Destroying toplevel on :1"
    destroy .t1
    sleep 1000
    puts "Killing Xvnc"
    exec kill $pid
    sleep 1000
    puts "Test passed"
}

coroutine run try {main $argv} on error {- info} {
    puts stderr [dict get $info -errorinfo]
} finally exit

vwait forever

I also tried using a separate interp for creating the window on the virtual display, but Tk still crashes when the Xvnc instance is killed after the interp has already been deleted.

User Comments: serhiy.storchaka added on 2026-09-23 20:41:21:

Following up on my earlier comment: I tried it. Closing the display when its last window is destroyed, deferred to idle time because Tk_DestroyWindow() still uses the display after that point, makes exactly this scenario pass — with the toplevel on the second display destroyed before the server is killed, the application keeps running instead of dying with the XIO error.

It is not enough in general, though. If a window is created on that display again after it was closed, a frame works, but a label fails on the third round:

X Error of failed request:  BadLength
  Major opcode of failed request:  51 (X_SetFontPath)

so the font layer keeps a reference to the closed display. TkCloseDisplay() releases the clipboard, atoms, error handlers and GCs, but not borders, bitmaps, colors, cursors and fonts, and says so itself: "There is more to clean up, we leave it at this for the time being." The same two cases and the same measurements are described in [923174].


serhiy.storchaka added on 2026-09-18 16:47:11:

Still present in main. Tk keeps the connection to a display open after its last window is destroyed: closing a display when it is no longer used has been disabled in Tk_DestroyWindow() since 2002 (#if !defined(_WIN32) && defined(NOT_YET) in tkWindow.c) because of shutdown order problems, so displays are only closed at exit, and the fatal I/O error handler of Xlib terminates the process when the server goes away. Enabling that code requires making all per-display resources releasable first.