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

How to check if server is already running? #60

Closed
chtenb opened this issue May 22, 2013 · 19 comments
Closed

How to check if server is already running? #60

chtenb opened this issue May 22, 2013 · 19 comments

Comments

@chtenb
Copy link
Contributor

chtenb commented May 22, 2013

Title explains. I want the check if the server is already running, before starting it.

@nosami
Copy link
Contributor

nosami commented May 22, 2013

I'm going to rewrite this section of code https://github.com/nosami/OmniSharpServer/blob/master/OmniSharp/Program.cs#L54

to use a lock file instead of a mutex as mutex doesn't work on Mono (without setting an environment variable see http://www.mono-project.com/Release_Notes_Mono_2.8#Shared_handles_are_disabled_by_default). It will then be a simple case of checking for the lockfile.

Expect that to be done tonight (GMT)

@nosami
Copy link
Contributor

nosami commented May 22, 2013

I just committed a fix for this. A lockfile is created with name "lockfile-" + port in the exe folder when the server is running. It is deleted when the stop server command is ran or ctrl-c is pressed.

It isn't deleted when the process is aborted. The server has an exclusive lock on the file, so ideally to detect if it is running you should check for the existence of the file and also attempt to read it.

@chtenb
Copy link
Contributor Author

chtenb commented May 24, 2013

It seems as if there is no lock file present when I run the server.
I updated my fork and recompiled. I ran the command find . -name '*lock*' in my home directory, but it gives no results.
What is going wrong?

@nosami
Copy link
Contributor

nosami commented May 24, 2013

The code to create the lockfile is here https://github.com/nosami/OmniSharpServer/blob/master/OmniSharp/Program.cs#L60. It gets created in the same location as OmniSharp.exe for me.

@chtenb
Copy link
Contributor Author

chtenb commented May 24, 2013

Thanks for your reply. It appears I had to pull the new server subrepo manually, my mistake :). Having done so, I indeed get a lockfile at the pointed location.
Currently trying to check for the file, which is not as trivial as it should be.
FYI, I will be away for two day being unable to work on this and respond to comments.

@chtenb
Copy link
Contributor Author

chtenb commented May 28, 2013

The lockfile is now checked correctly. The only thing that's left to do is the automatic call of the :stop server" function. Ideally the server is stopped when the last vim instance is closed. I don't think it is reasonably possible to do so without using external, os specific, commands.

http://stackoverflow.com/questions/16798740/call-function-when-last-vim-instance-is-closing

I will prompt the user instead, which I just implemented.

@chtenb chtenb closed this as completed May 28, 2013
@chtenb chtenb reopened this May 28, 2013
@chtenb
Copy link
Contributor Author

chtenb commented May 28, 2013

The bug in #68 is related to this issue.
It looks like the lockfile is always readable, even if the server is running.
When I start the server, the lockfile is created. However, when I check for readability using filereadable (vim function) or when I manually read or write the lockfile, nothing says the file is locked.
Can you confirm that on windows and/or linux?

@nosami
Copy link
Contributor

nosami commented May 29, 2013

Your code works as designed ( I think ) on Windows. Haven't been able to produce a scenario where 2 instances of the server are started.

@chtenb
Copy link
Contributor Author

chtenb commented May 29, 2013

If I start the server (my fork) and run :echo OmniSharp#ServerIsRunning() it returns 0, though the mono process is running and a quick look in the bin/Debug directory confirms that the lock-2000 file is actually there. To test this, you should also pull the latest bugfix in my fork.

To check the correctness of my code, the little function OmniSharp#ServerIsRunning() is the relevant one.

@nosami
Copy link
Contributor

nosami commented May 29, 2013

I get 1 when I run that command. I guess file locking works differently on linux 😕

@chtenb
Copy link
Contributor Author

chtenb commented May 29, 2013

:( Too bad. I think my PR would work for windows users, but I haven't tested on windows. However, the merge should be postponed until the file locking works on linux too.

@nosami
Copy link
Contributor

nosami commented May 29, 2013

Maybe this helps? http://cs.potsdam.edu/cgi-bin/man/man2html?1+mono Try setting environment variable MONO_STRICT_IO_EMULATION. Not near my linux machine to test, I'm afraid.

If it works, it should be possible to set that from within the application server.

@nosami
Copy link
Contributor

nosami commented May 29, 2013

Maybe something like this http://duplicati.googlecode.com/svn-history/r980/trunk/thirdparty/UnixSupport/File.cs is needed for Unix support.

@chtenb
Copy link
Contributor Author

chtenb commented May 29, 2013

Looks good! Could that be pasted into Omnisharp straight?

@nosami
Copy link
Contributor

nosami commented May 29, 2013

I guess so. Looks like it just needs a reference to Mono.Unix. Currently downloading a linux ISO so I can run some tests on linux when I'm away from home. Going slooowly though.

@nosami
Copy link
Contributor

nosami commented Jun 2, 2013

I added the lock code mentioned above here OmniSharp/omnisharp-server@c0d0f4b but it just doesn't work and I'm ready to give up with it. I think that on linux the best way of doing this would be to grep the output of 'ps ef'. I'm closing this issue now but we continue this on #68

@nosami nosami closed this as completed Jun 2, 2013
@chtenb
Copy link
Contributor Author

chtenb commented Jun 4, 2013

Proposal. Wouldn't it be neat to do the following?

To check if the server is running, we can just send a request. If the request is properly answered, we know it is properly running, and otherwise not.

I think this way is better than the way we do it now. Also it is going to be more compatible with multiple instances of omnisharp for multiple projects, even if they are started without providing the -p flag.
What is your opinion on this?

@chtenb
Copy link
Contributor Author

chtenb commented Jun 21, 2013

Any opinions about this?

@nosami
Copy link
Contributor

nosami commented Jun 21, 2013

Seems like it would be ok so long as the exception comes back fast enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants