[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Bug reports
. . -> [Subject]  A access violation caused by race condition
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

A access violation caused by race condition

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Kahenraz   (42 posts)  [Biography] bio
Date Wed 21 Sep 2016 03:01 AM (UTC)
Message
I have an external script file which I have set to automatically recompile changes "always" so that it's faster to test and debug with an external editor.

The problem I'm encountering is that sometimes MUSH will report a sharing violation:

---------------------------
MUSHclient
---------------------------
A sharing violation occurred while accessing C:\data\games\Mush\worlds\scripts\functions.lua.
---------------------------
OK
---------------------------

This is most likely due MUSH trying to read from the file while my editor is still writing to it.

A workaround for this would be to retry on a delay (sleep every 10ms or so) and if there is still an access violation after say, 3-5 seconds then report the access violation.
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Wed 21 Sep 2016 08:48 AM (UTC)
Message
Huh. This is the sort of thing I expect my OS to abstract away.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Kahenraz   (42 posts)  [Biography] bio
Date Reply #2 on Wed 21 Sep 2016 02:25 PM (UTC)
Message
You can't abstract away an IO error because it's blocking.
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Wed 21 Sep 2016 06:45 PM (UTC)
Message
Quote:
You can't abstract away an IO error because it's blocking.

Eh. None of that needs to be true with only one writer.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Kahenraz   (42 posts)  [Biography] bio
Date Reply #4 on Wed 21 Sep 2016 06:58 PM (UTC)

Amended on Wed 21 Sep 2016 06:59 PM (UTC) by Kahenraz

Message
You can't always read from a file while it's being written to. That's the race condition.

MUSH tries to detect changes in the file but doesn't handle instances where the write isn't atomic and needs to wait until the read is finished.

Just keep trying to read the file on a delay and with a reasonable timeout.

A simpler alternative is to copy the file to a unique temporary file and read it from there. I can't confirm but I'm pretty sure that the copy will block until it has a valid file handle. Just remember to delete the copy afterwards.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Thu 22 Sep 2016 03:55 AM (UTC)
Message
Quote:

A access violation caused by race condition


Do you mean a sharing violation? They aren't the same thing.

Some editors always write to a temporary file and rename at the last moment.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Kahenraz   (42 posts)  [Biography] bio
Date Reply #6 on Thu 22 Sep 2016 03:58 AM (UTC)
Message
I'm not certain where the error is coming from exactly but it happens between the time I save the file and MUSH tries to load it.

The error is annoying because I then have to switch to MUSH and click the little box to close before I can continue.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Thu 22 Sep 2016 09:19 PM (UTC)
Message
You can turn off auto-reloading and just hit Shift+Ctrl+R when you are ready.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Kahenraz   (42 posts)  [Biography] bio
Date Reply #8 on Thu 22 Sep 2016 09:22 PM (UTC)
Message
I like the auto-reload functionality because it's easier to just reload the script every time I make a change.

All I want is for the client to make an effort to recover from this error rather than throwing up the message box outright.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Thu 22 Sep 2016 09:56 PM (UTC)
Message
Well, this is the first time this was reported in over 10 years. I don't really want to build in a delay, or have the added complexity of noticing a file changes, but keeping on trying to read it.

I've changed it from a dialog box to a message in the output window. If you see the error message, then you can force a reload.


https://github.com/nickgammon/mushclient/commit/aa0cd16

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


2,679 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]