Tcl Source Code

View Ticket
Login
Ticket UUID: ce32712f83f0d30051adb6a53e11f9e338a9944
Title: Inconsistent locking during zipfs initialization
Type: Bug Created on: 2025-10-03 10:04:51
Submitter: apnadkarni Assigned to: nobody
Subsystem: - New Builtin Commands Severity: Minor
Priority: 5 Medium Last modified: 2025-12-09 09:01:27
Status: Open Closed by: nobody
Resolution: None Closed on:
Version: 9.0.2
Description:

Both the following sequences are seen in tclZipFs.c

    ReadLock();
    if (!ZipFS.initialized) {
	ZipfsSetup();
    }

and

    WriteLock();
    if (!ZipFS.initialized) {
	ZipfsSetup();
    }
  • Why is ZipfsSetup under a read lock in some cases and write locks in others? Does not seem to make sense.
  • How is a read lock sufficient given that ZipfsSetup modifies the internal structures?

I had added a TODO comment questioning this when fixing zipfs bugs during the 9.0 beta but forgot to revisit and just saw it today :-(

User Comments:
dkf added on 2025-10-07 14:11:25:

Since it's a once-per-process setup, the flag is likely set to true before the process launches any more threads (that read the vfs). The different locks may be for the code that follows.

If my thoughts are correct, moving the call to ZipfsSetup() outside the lock (and having it recheck the flag inside the call as well as using its own lock, for double-checked locking) is likely to be the optimal approach; the case when two threads vie of the new lock is expected to be very rare.

The memory barrier due to the function call is probably enough.


jan.nijtmans added on 2025-12-09 09:01:27:

Ping? What's the status of this?