This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 40552 - [36cat] Can not save file. Invalid Lock
Summary: [36cat] Can not save file. Invalid Lock
Status: CLOSED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Filesystems (show other bugs)
Version: 3.x
Hardware: PC Linux
: P1 blocker (vote)
Assignee: rmatous
URL:
Keywords: RANDOM
Depends on:
Blocks:
 
Reported: 2004-02-27 09:36 UTC by vanob
Modified: 2008-12-22 20:24 UTC (History)
7 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
ide.log (423.68 KB, text/plain)
2004-02-27 09:40 UTC, vanob
Details
ide.log (63.18 KB, text/plain)
2004-03-09 12:07 UTC, vanob
Details
please disregard the previous ide.log. Now attaching the real one. (98.23 KB, text/plain)
2004-03-09 12:10 UTC, vanob
Details
Used workaround (1.90 KB, patch)
2004-03-10 13:53 UTC, Petr Nejedly
Details | Diff
Fixed diff. The previous one was wrong (bad placement of toString method) (1.96 KB, patch)
2004-03-11 09:59 UTC, Petr Nejedly
Details | Diff
ide.log (72.20 KB, text/plain)
2004-03-23 06:58 UTC, vanob
Details
Here is hot fix. Please test it if you can (713 bytes, patch)
2004-03-23 12:17 UTC, rmatous
Details | Diff
Binary patch for ../netbeans/lib/patches (14.97 KB, application/octet-stream)
2004-03-23 15:34 UTC, rmatous
Details
ide.log (184.88 KB, patch)
2004-03-24 11:38 UTC, vanob
Details | Diff
This example may be interesting for better understanding of finalization. (1.11 KB, text/plain)
2004-03-24 13:26 UTC, Petr Nejedly
Details
Binary patch (11.58 KB, application/octet-stream)
2004-03-24 14:14 UTC, rmatous
Details
Here is diff related to last binary patch (3.05 KB, patch)
2004-03-24 14:19 UTC, rmatous
Details | Diff
ide.log (246.50 KB, text/plain)
2004-03-29 11:54 UTC, vanob
Details
Patch for nb36 - please review (without diagnostic) (2.24 KB, patch)
2004-03-29 16:37 UTC, rmatous
Details | Diff
Binary patch - Vano please could you test with this binary patch again and provide output of it. (12.08 KB, application/octet-stream)
2004-03-29 17:48 UTC, rmatous
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vanob 2004-02-27 09:36:52 UTC
[ JDK VERSION : J2SE 1.4.2_02 ]

I searched for this bug, but could not find it.
I remember that the bug is filed so if it's a duplicate, sorry and close it.

After working in the editor
I cannot save the file. 
attaching ide.log
Comment 1 vanob 2004-02-27 09:40:35 UTC
Created attachment 13696 [details]
ide.log
Comment 2 psuk 2004-02-27 16:08:18 UTC
It seems like 3rd party module (struts support from James Holmes)
caused the problem.

(assuming that it was not rewritten to use new windowing system)

Assigning to core for evaluation.

Comment 3 Milos Kleint 2004-03-01 13:53:56 UTC
the window system exceptions  in the log are related to issue #40624.
IMHO these cannot cause the described problem of not being able to
save the file.

moving to editor for evaluation. Justification: The user describes
that he/she was working in the editor.
Comment 4 Miloslav Metelka 2004-03-03 13:57:18 UTC
Not sure why there is that invalid lock exception. Reassigning to
openide/filesystems for evaluation.
Comment 5 rmatous 2004-03-03 14:13:32 UTC
Known problem with FileEntry.takeLock: one instance of FileLock is
distributed from FileEntry and is shared between independent pieces of
code. As soon as one ownere of lock releases it the others keep
invalid locks. 
Comment 6 Petr Nejedly 2004-03-04 10:28:47 UTC
But:
1. the exception is thrown because of null lock (see 
   MultiFileObject.java:528)
2. DES is already (from 17/2/2004) checking lock presence and validity
   (see DataEditorSupport.java:402-404) so the only way it can pass
   null or invalid lock is to obtain it from takeLock() method

JavaEditor takes lock through EditorSupport from MultiDataObject
MDO does its own caching and validity check, so it can only pass null
lock if it gets it from FileObject. BTW: The Entry.takeLock Javadoc is
wrong, it states it can return null, but it shouldn't.

Can the FIleObject actually return null lock?
Comment 7 Petr Nejedly 2004-03-04 11:43:01 UTC
Radek, can you look at it more? I don't see how it can happen now
(after 25/2/2004)

Vano, is it reproducible? If it is, I can provide a debugging patch
and we may be able to nail it down even for 3.6
If you can't reproduce it, please downgrade it to P3 and mark it with
RANDOM keyword. Without more info I can't target the fix for 3.6
 
Comment 8 rmatous 2004-03-04 12:22:46 UTC
DES:405 - getFileImpl ().getOutputStream (fileLock) 
MFO.testLock:528  - if (lock == null) FSException.io ("EXC_InvalidLock" ..

[simplified] So, in MFO.testLock is compared "lock" with "fileLock".
But first must be true that MFO is ever locked (lock != null) which
isn't true according attached stacktrace.  

 ---
Result: 
Attached ied.log comes from  20/2/2004. I think your fix (25/2/2004)
should  help - at least decrease probability . 

Priority decreased to P4 because your fix isn't 100%. Test lock for
validity and its usage must be atomic and exclusive which currently isn't.

But please if you can reproduce  or it occures regularly (on last dev
builds) then please don't hasitate and increase priority again !
Comment 9 vanob 2004-03-09 11:59:47 UTC
It happened again.
using Q-build
200403040727.

This bug dirves me crazy.
I lost 100 lines of code because of this!!!

I know we're in a high resistance mode but this bug
MUST be fixed by 3.6

If needed (nobody's going to fix this bug by 3.6) I will call for
NetCat participants to vote.
and fix this bug.
Comment 10 vanob 2004-03-09 12:07:20 UTC
Created attachment 13893 [details]
ide.log
Comment 11 vanob 2004-03-09 12:10:20 UTC
Created attachment 13894 [details]
please disregard the previous ide.log. Now attaching the real one.
Comment 12 Marian Mirilovic 2004-03-09 13:11:41 UTC
Vano, 
do you have steps to reproduce? Start with new userdir ....

Thanks for help .....
Comment 13 Petr Nejedly 2004-03-10 13:50:18 UTC
OK, I've just commited a workaround to dev trunk.
Comment 14 Petr Nejedly 2004-03-10 13:53:57 UTC
Created attachment 13922 [details]
Used workaround
Comment 15 Petr Nejedly 2004-03-10 14:07:47 UTC
Yarda, could you please review the workaround while Radek is on vacations?
Comment 16 Petr Nejedly 2004-03-11 09:59:58 UTC
Created attachment 13938 [details]
Fixed diff. The previous one was wrong (bad placement of toString method)
Comment 17 Jaroslav Tulach 2004-03-11 10:05:39 UTC
The fix definitively improves the current state.
Comment 18 Petr Nejedly 2004-03-11 15:32:45 UTC
Integrated into release36

openide/src/org/openide/filesystems/MultiFileObject.java,v1.114.4.1
openide/loaders/src/org/openide/text/DataEditorSupport.java,v1.13.4.1
Comment 19 Marian Mirilovic 2004-03-14 12:23:28 UTC
Vano, 
can you reproduce it now ?
If so reopen , thanks in advance....

I can't - verified in [nb_36_rc1](20040313-0952)
Comment 20 vanob 2004-03-23 06:57:10 UTC
NetBeans 3.6 RC1

Emptry userdir:
Generated a property from bean patterns node.
The file can not be saved.

Just a comment:
This bug happened only after some action:
1. Import Wizard
2. Generate property from bean patterns node

It does not happen if I don't use above actions.
Hope this will help.
Comment 21 vanob 2004-03-23 06:58:55 UTC
Created attachment 14092 [details]
ide.log
Comment 22 Petr Nejedly 2004-03-23 11:30:56 UTC
Thanks for the report. With the improved debugging info I put into
code last time it points to a problem in filesystems.

Radku, please note that the lock I'm passing thinks it is valid (it
things so even after throwing the exception as is visible from:
"org.openide.filesystems.MultiFileObject$MfLock@2023c2 for
com/silkroad/srm3/form/ChargeForm.java valid=true"

What is very suspicious to me is that o.o.f.FileLock contains no
synchronization at all, but that don't necesarilly have to be the problem.
Comment 23 Petr Nejedly 2004-03-23 11:32:32 UTC
New high priority issue in release36, cc-ing interested parties.
Comment 24 rmatous 2004-03-23 12:17:01 UTC
Created attachment 14096 [details]
Here is hot fix.  Please test it if you can
Comment 25 vanob 2004-03-23 13:01:51 UTC
I don't use cvs version.
What is the shortest way for me to test the hotfix?

If it's necessary I will try cvs version
Comment 26 Jan Chalupa 2004-03-23 13:40:33 UTC
Radek or Petr, please provide a binary patch for testing. Thanks.
Comment 27 rmatous 2004-03-23 15:34:02 UTC
Created attachment 14102 [details]
Binary patch for  ../netbeans/lib/patches
Comment 28 Petr Nejedly 2004-03-24 08:29:19 UTC
This hotfix seems very safe to me.
To be clear, it is a workaround that makes the behaviour of the MfLock
consistent even when its internal structures go out of sync.
This way, should anything go wrong, it will trigger the workaround
I've integrated before and allow transparent handling of the internal
inconsistency.
Comment 29 vanob 2004-03-24 11:36:12 UTC
This happened again event after applying binary patch.
So now it's another exception FileAlreadyLockedException.
attaching ide.log
Comment 30 vanob 2004-03-24 11:38:24 UTC
Created attachment 14119 [details]
ide.log
Comment 31 Petr Nejedly 2004-03-24 12:55:07 UTC
I believe I've found aprobable scenario on what is going on inside to
trigger this problem:
1. something acquires a lock on MFO (which locks the delegate)
2. it releases the reference to it without releaseLock()
3. gc occurs, clears the MFO.lock weak reference and puts the MfLock
   in the finalization queue.
4. editor locks the MFO again (works because the lock.get() gives
   null result)
5. finalize() on the first MfLock is performed, clears the reference
   to the second lock.
6. editor tries to get OutputStream, passing the second MfLock,
   which has valid = true, but the MFO doesn't know it now (because
   of step 5)

This is what I realized before reading your last report.
There is still one thing missing in the scenario, and that is how
can it get new MfLock in step 4, when the delegate file should be
still locked. Possible explanation is that the sublocks ("GCed" now)
were put into the finalization queue before the MfLock...
Comment 32 Petr Nejedly 2004-03-24 13:26:34 UTC
Created attachment 14120 [details]
This example may be interesting for better understanding of finalization.
Comment 33 rmatous 2004-03-24 14:10:04 UTC
You are definitely right. I played with the same idea. I'll attach
binary patch which should solve this problem. But the primary culprit
is unknown code that gets FileLock , doesn't release it and then let
it garbage collected - I add into patch also diagnostic that should
reveal who is responsible.
Comment 34 rmatous 2004-03-24 14:14:26 UTC
Created attachment 14124 [details]
Binary patch
Comment 35 rmatous 2004-03-24 14:19:03 UTC
Created attachment 14125 [details]
Here is diff related to last binary patch
Comment 36 vanob 2004-03-25 07:48:56 UTC
I deleted old fs.jar from lib/patches and put new fs2.jar there.
Is it right?

Comment 37 rmatous 2004-03-25 09:38:45 UTC
Yes.
Comment 38 _ ttran 2004-03-29 08:25:29 UTC
Vano, can you please test the patch and let us know the result?  We
are very close to the release deadline and would like to resolve this
issue asap.  Thanks
Comment 39 vanob 2004-03-29 09:53:49 UTC
I'm currently testing it. No problems so far.
Could you please tell me the timeframe for testing and I will close it 
by that time if there is no problems.
Comment 40 rmatous 2004-03-29 10:05:20 UTC
Timeframe: ASAP 

This patch also contains some diagnostic (    
lockedByTrace.printStackTrace(System.err) in lock.diff attachment) -
I'm eager to know if there is any ouput  of it. 
Comment 41 vanob 2004-03-29 11:52:24 UTC
I looked at ide.log and discovered lot of exceptions there.
I think it's your diagnosed exceptions. attaching ide.log
Comment 42 vanob 2004-03-29 11:54:43 UTC
Created attachment 14184 [details]
ide.log
Comment 43 Petr Nejedly 2004-03-29 14:02:25 UTC
Two things:
1. The debugging part (which won't go to rel36 anyway) is wrong, it
 fails to filter only the problematic locks. This is why there is so
 many entries in the log (false alarms) ;-(
2. I'd place the delegate releasing out of the conditional block, as
 the condition will always be false during finalize (reference already
 cleared), but it would be nice to speedup releasing the delegates.
 Note: they should be released from their finalize() as a result of
 the same GC run, so it should make very little difference.
Comment 44 rmatous 2004-03-29 14:33:59 UTC
>Two things:
>1. The debugging part (which won't go to rel36 anyway) is wrong, it
> fails to filter only the problematic locks. This is why there is so
> many entries in the log (false alarms) ;-(
>
You are right, I'm aware of it.

>2. I'd place the delegate releasing out of the conditional block, as
> the condition will always be false during finalize (reference already
> cleared), but it would be nice to speedup releasing the delegates.
> Note: they should be released from their finalize() as a result of
> the same GC run, so it should make very little difference.
>
I agree.

So, I''ll ask for review today, prepare new  patch for release36
without diagnostic and including integration of  your 2. comment. So,
I hope you will review this patch. Then I prepare one binary patch
just for testing - this patch will include integration of both your
comments. I hope Vano will review this binary patch and will provide
output of it.
Comment 45 rmatous 2004-03-29 16:32:14 UTC
Fixed into trunk.

/cvs/openide/src/org/openide/filesystems/FileLock.java,v  <-- 
FileLock.java
new revision: 1.12; previous revision: 1.11

/cvs/openide/src/org/openide/filesystems/MultiFileObject.java,v  <-- 
MultiFileObject.java
new revision: 1.118; previous revision: 1.117
Comment 46 rmatous 2004-03-29 16:37:34 UTC
Created attachment 14191 [details]
Patch for nb36 - please review (without diagnostic)
Comment 47 rmatous 2004-03-29 17:48:31 UTC
Created attachment 14194 [details]
Binary patch - Vano please could you test with this binary patch again and provide output of it.
Comment 48 Petr Nejedly 2004-03-30 11:35:01 UTC
I've reviewed the last patch.
Comment 49 rmatous 2004-03-30 14:23:53 UTC
I plan to integrate reviewed patch into nb3.6 today.
Comment 50 vanob 2004-03-30 14:35:24 UTC
I'm testing fs3.jar patch and no problems so far.
Comment 51 rmatous 2004-03-30 16:25:25 UTC
Fixed into release36.

/cvs/openide/src/org/openide/filesystems/MultiFileObject.java,v  <-- 
MultiFileObject.java
new revision: 1.114.4.2; previous revision: 1.114.4.1
Comment 52 Marian Mirilovic 2005-12-14 15:57:15 UTC
old issue without any news - closed