Opened 12 years ago

Last modified 8 years ago

#859 closed defect (Fixed)

datadirectory locking doesn't work on windows?

Reported by: arma Owned by:
Priority: Low Milestone:
Component: Core Tor/Tor Version:
Severity: Keywords:
Cc: arma, coderman, Sebastian, nickm Actual Points:
Parent ID: Points:
Reviewer: Sponsor:


We have a user on #tor who says he's running 3 Tor clients on a single

Lirezh_off> there is a lock file but it is ignored

Lirezh_off> i tried to run 3 tor at the same time, it didnot seem to make a

did the newer tors overwrite the lock file?
or did it stay with the first one

Lirezh_off> second
Lirezh_off> lock and state were changed, but only with the first launch
Lirezh_off> the other files are untouched atm

Perhaps we are not locking correctly on Windows?

[Automatically added by flyspray2trac: Operating System: All]

Child Tickets

Change History (6)

comment:1 Changed 12 years ago by Sebastian

I'm looking into the problem. It was easy to reproduce with

Currently, I have one main idea: Could it be that locking 0 bytes of a file actually achieves nothing?

comment:2 Changed 12 years ago by Sebastian

One approach that I found might be using _sopen_s instead of open for windows...

comment:3 Changed 12 years ago by Sebastian

proposed patch (locking beyond the end of the file is allowed, and in this case seems to be necessary):

Index: src/common/compat.c
--- src/common/compat.c (revision 17242)
+++ src/common/compat.c (working copy)
@@ -508,7 +508,7 @@


#ifdef WIN32

_lseek(fd, 0, SEEK_SET);

  • if (_locking(fd, blocking ? _LK_LOCK : _LK_NBLCK, 0) < 0) {

+ if (_locking(fd, blocking ? _LK_LOCK : _LK_NBLCK, 1) < 0) {

if (errno != EDEADLOCK)

log_warn(LD_FS,"Couldn't lock \"%s\": %s", filename, strerror(errno));


@@ -542,7 +542,7 @@

log_info(LD_FS, "Unlocking \"%s\"", lockfile->filename);

#ifdef WIN32

_lseek(lockfile->fd, 0, SEEK_SET);

  • if (_locking(lockfile->fd, _LK_UNLCK, 0) < 0) {

+ if (_locking(lockfile->fd, _LK_UNLCK, 1) < 0) {

log_warn(LD_FS,"Error unlocking \"%s\": %s", lockfile->filename,



comment:4 Changed 12 years ago by nickm

applies as r17244. This is tested to work?

comment:5 Changed 12 years ago by nickm

flyspray2trac: bug closed.

comment:6 Changed 8 years ago by nickm

Component: Tor ClientTor
Note: See TracTickets for help on using tickets.