Re: Acquiring exclusive lock on a file seems to not be working anymore
Michael B Allen <[email protected]> Tue, 9 Aug 2016 23:47:03 -0400
| Newsgroups | gmane.network.samba.java |
|---|---|
| Message-ID | <CAGMFw4jHzuK97ryrOCM+bw0QFQzUHOv8Y7OpFHCfZBPGvLk5tw@mail.gmail.com> |
On Tue, Aug 9, 2016 at 6:03 AM, Moritz Bechler <[email protected]> wrote: > Hi, > > > has anyone noticed that the SmbFile.FILE_NO_SHARE option which is suppose= d > to grant an exclusive lock on a file, is not working anymore? > I wrote this small example program, which I run under windows 7 machine. > The program basically starts 45 threads which try to append the text > =E2=80=9Ctest\n=E2=80=9D in the same file at the same time, incrementing = a counter if a > IOException =E2=80=9CFile used by another process=E2=80=9D occurs. > > > At the end, it is expected to have the file text.txt containing N rows wi= th > the word =E2=80=9Ctest=E2=80=9D, and the number 45 =E2=80=93 N printed in= the console (the number of > threads that got =E2=80=9CFile used by another process=E2=80=9D exception= ). > However, the result is different on each execution and never correct =E2= =80=93 the > number of rows containing =E2=80=9Ctest=E2=80=9D in the test.txt file plu= s the number > printed in the console is always smaller than 45, which indicates that > locking is not working at all. > > Yep, there is a bug - but it's not the locking that is broken, it's > SmbFileOutputStream's append mode. It does use > Trans2QueryFSInformationResponse to retrieve the current file length as i= t > calls SmbFile.length before opening it (which does not follow the sharing > semantics and probably has no consistency guarantees whatsoever). Therefo= r > your file pointer will be set to a stale position and you do not actually > append but overwrite already present data. Nice. > > ( Patch, which may or may not apply cleanly: > https://github.com/AgNO3/jcifs-ng/commit/022842a1685293335e918a2a1d5416cf= 39bccdd9 > ) Hi Moritz, Thanks for finding this and sharing your fix. I have added this to the TODO list. As usual no ETA for actually being applied. Mike --=20 Michael B Allen Java Active Directory Integration http://www.ioplex.com/