Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LockFiles with adjustments #1357

Closed
wants to merge 18 commits into from
Closed

LockFiles with adjustments #1357

wants to merge 18 commits into from

Conversation

pjf
Copy link
Member

@pjf pjf commented Aug 9, 2015

This is #1265, but with the addition of tests and extra garbage collection. Specifically we need reviewed:

@Postremus
Copy link
Contributor

I opened the gui. I then wanted to install OPM with the cli. Got this error:

C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\Cmdline\bin\Debug>Cmd
Line.exe install OuterPlanetsMod

Unbehandelte Ausnahme: CKAN.RegistryInUseKraken: Eine Ausnahme vom Typ "CKAN.Reg
istryInUseKraken" wurde ausgelöst.
   bei CKAN.RegistryManager..ctor(String path, KSP ksp) in C:\Users\Martin\Docum
ents\Visual Studio 2015\Projects\CKAN\Core\Registry\RegistryManager.cs:Zeile 49.

   bei CKAN.RegistryManager.Instance(KSP ksp) in C:\Users\Martin\Documents\Visua
l Studio 2015\Projects\CKAN\Core\Registry\RegistryManager.cs:Zeile 146.
   bei CKAN.KSP.get_RegistryManager() in C:\Users\Martin\Documents\Visual Studio
 2015\Projects\CKAN\Core\KSP.cs:Zeile 33.
   bei CKAN.KSP.get_Registry() in C:\Users\Martin\Documents\Visual Studio 2015\P
rojects\CKAN\Core\KSP.cs:Zeile 38.
   bei CKAN.KSP.ScanGameData() in C:\Users\Martin\Documents\Visual Studio 2015\P
rojects\CKAN\Core\KSP.cs:Zeile 321.
   bei CKAN.CmdLine.MainClass.Scan(KSP ksp_instance, IUser user, String next_com
mand) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\Cmdline\Main
.cs:Zeile 338.
   bei CKAN.CmdLine.MainClass.Main(String[] args) in C:\Users\Martin\Documents\V
isual Studio 2015\Projects\CKAN\Cmdline\Main.cs:Zeile 188.

@pjf
Copy link
Member Author

pjf commented Aug 9, 2015

I opened the gui. I then wanted to install OPM with the cli. Got this error:

Hooray! We should probably make that more user-friendly, shouldn't we?

But hooray for the correct kraken being thrown.

@Postremus
Copy link
Contributor

Yes, the user friendly message should be shown.

I ran the Tests. Most of them throw a "The process cannot access the file "registry.json.locked" because it is being used by another process." now.

lockfile_stream = new FileStream(lockfile_path, FileMode.CreateNew, FileAccess.Write, FileShare.None, 512, FileOptions.DeleteOnClose);

// Write the current process ID to the file.
StreamWriter writer = new StreamWriter(lockfile_stream);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The StreamWriter should be closed and disposed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good catch! We need to keep the FileStream open, but not the StreamWriter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we can't close the StreamWriter, as that would close the underlying file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we can't dispose it either, as that also releases the lock. Adjusting code now.

pjf added a commit to pjf/CKAN that referenced this pull request Aug 9, 2015
@pjf
Copy link
Member Author

pjf commented Aug 9, 2015

Updates applied include:

  • Refactoring of CmdLine/Main to simplify the switch statement and code flow.
  • Fixed an instance of trying to clean up after discovering a lock resulting in... another lock error.
  • Made the error message a little more user friendly ("CKAN already running" rather than "registry locked")
  • StreamWriter is disposed of on lock release.

@Postremus
Copy link
Contributor

Opening the gui, then closing it throws this:

Unhandled exception:
System.ObjectDisposedException: Auf eine geschlossene Datei kann nicht zugegriffen werden.
   bei System.IO.__Error.FileNotOpen()
   bei System.IO.FileStream.Flush(Boolean flushToDisk)
   bei System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
   bei System.IO.StreamWriter.Dispose(Boolean disposing)
   bei System.IO.TextWriter.Dispose()
   bei CKAN.RegistryManager.ReleaseLock() in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\Core\Registry\RegistryManager.cs:Zeile 141.
   bei CKAN.RegistryManager.Dispose(Boolean safeToAlsoFreeManagedObjects) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\Core\Registry\RegistryManager.cs:Zeile 89.
   bei CKAN.RegistryManager.Dispose() in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\Core\Registry\RegistryManager.cs:Zeile 79.
   bei CKAN.Main..ctor(String[] cmdlineArgs, GUIUser User, Boolean showConsole) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\GUI\Main.cs:Zeile 240.
   bei CKAN.GUI.Main_(String[] args, Boolean showConsole) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\GUI\Program.cs:Zeile 35.
   bei CKAN.GUI.Main(String[] args) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\GUI\Program.cs:Zeile 17.
   bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   bei System.Threading.ThreadHelper.ThreadStart() 

@pjf
Copy link
Member Author

pjf commented Aug 9, 2015

@Postremus : Resource disposal adjusted! Travis seems to like this better, too. :)

@Postremus
Copy link
Contributor

The Tests still throw an "The process cannot access the file "registry.json.locked" because it is being used by another process." at me.

@pjf
Copy link
Member Author

pjf commented Aug 9, 2015

@Postremus : I've found a very obvious suspect for the locking issues when running tests! I hope badfc43 brings great joy!

@pjf
Copy link
Member Author

pjf commented Aug 9, 2015

@Postremus : And another patch, but I suspect you'll see at least one more bug, but we're almost there. :)

// This is not entirely necessary, but we can show a nicer error message this way.
try
{
#pragma warning disable 219
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be one for @mgsdk (who authored the change). I suspect calling RegistryManager.Instance(CurrentInstance).registry without an assignment generates a warning and/or requires an assignment, but I honestly haven't tested that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for assigning a variable but never using it, CS0219. Since I know it wouldn't be used, I thought I would reduce the warnings in the output.

pjf added 3 commits August 19, 2015 14:53
Disposing of the writer also disposes of the stream, but the
other way around (which we had) causes great sadness, or at least
an unhandled exception.
This should make windows users happy, as otherwise the files
can't be deleted at all!
This means our tests (and possibly other code) can get it to release
locks properly.
@Postremus
Copy link
Contributor

  1. Needs a rebase
  2. Got this exception when selecting an instance.
Unhandled exception:
System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   bei CKAN.KSPManager.SetCurrentInstance(String name) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\Core\KSPManager.cs:Zeile 238.
   bei CKAN.ChooseKSPInstance.UseSelectedInstance() in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\GUI\ChooseKSPInstance.cs:Zeile 86.
   bei CKAN.ChooseKSPInstance.SelectButton_Click(Object sender, EventArgs e) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\GUI\ChooseKSPInstance.cs:Zeile 74.
   bei System.Windows.Forms.Control.OnClick(EventArgs e)
   bei System.Windows.Forms.Button.OnClick(EventArgs e)
   bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   bei System.Windows.Forms.Control.WndProc(Message& m)
   bei System.Windows.Forms.ButtonBase.WndProc(Message& m)
   bei System.Windows.Forms.Button.WndProc(Message& m)
   bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   bei System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   bei CKAN.Main..ctor(String[] cmdlineArgs, GUIUser User, Boolean showConsole) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\GUI\Main.cs:Zeile 176.
   bei CKAN.GUI.Main_(String[] args, Boolean showConsole) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\GUI\Program.cs:Zeile 35.
   bei CKAN.GUI.Main(String[] args) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\GUI\Program.cs:Zeile 17.
   bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   bei System.Threading.ThreadHelper.ThreadStart() 

@Olympic1 Olympic1 added GUI Issues affecting the interactive GUI Cmdline Issues affecting the command line labels Feb 28, 2016
@Dazpoet
Copy link
Member

Dazpoet commented Apr 10, 2016

This still requires a rebase and, I assume, a solution to what @Postremus posted above.

politas pushed a commit to politas/CKAN that referenced this pull request Jul 13, 2016
techman83 pushed a commit to techman83/CKAN that referenced this pull request Jul 13, 2016
@politas
Copy link
Member

politas commented Jul 14, 2016

Closing this in favour of #1828, which continues the work

@politas politas closed this Jul 14, 2016
politas pushed a commit to politas/CKAN that referenced this pull request Jul 19, 2016
politas pushed a commit to politas/CKAN that referenced this pull request Jul 30, 2016
politas pushed a commit to politas/CKAN that referenced this pull request Aug 2, 2016
politas pushed a commit to politas/CKAN that referenced this pull request Aug 16, 2016

Verified

This commit was signed with the committer’s verified signature.
Part of KSP-CKAN#1357.
politas pushed a commit to politas/CKAN that referenced this pull request Aug 17, 2016

Verified

This commit was signed with the committer’s verified signature.
Part of KSP-CKAN#1357.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cmdline Issues affecting the command line GUI Issues affecting the interactive GUI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants