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

SingleInstanceService works correctly just for the first application run #645

Closed
vnashkev opened this issue May 25, 2020 · 3 comments
Closed

Comments

@vnashkev
Copy link

vnashkev commented May 25, 2020

After first start lock file with a port number is created

C:\Users\user\AppData\Local\Temp\user\netx\locks\http___localhost_jnlp.jnlp.

Lock file still exists after application termination.
Next time SingleInstanceServer fails to start with the following exception:

java.io.IOException: Cannot rename C:\Users\user\AppData\Local\Temp\user\netx\locks\http___localhost_jnlp.jnlp.temp to C:\Users\user\AppData\Local\Temp\user\netx\locks\http___localhost_jnlp.jnlp
	at net.adoptopenjdk.icedteaweb.io.FileUtils.createRestrictedFile(FileUtils.java:331)
	at net.adoptopenjdk.icedteaweb.io.FileUtils.createRestrictedFile(FileUtils.java:172)
	at net.sourceforge.jnlp.services.SingleInstanceLock.createWithPort(SingleInstanceLock.java:70)
	at net.sourceforge.jnlp.services.SingleInstanceLockTest.testCreateWithPort(SingleInstanceLockTest.java:34)

Test case demonstraits the problem:

public final class SingleInstanceLockTest
	extends NoStdOutErrTest
{
    @Test
    public void testCreateWithPort() 
    	throws Exception 
    {
    	final URL url = this.getClass().getClassLoader().getResource("net/sourceforge/jnlp/basic.jnlp");
        final JNLPFile jnlpFile = new JNLPFile(url.openStream(), url, new ParserSettings(false,false,false));
        
        assert jnlpFile!=null;
        
        final SingleInstanceLock sil = new SingleInstanceLock(jnlpFile);
        
        sil.lockFile.delete();
        assert sil.lockFile.exists()==false;
        
        sil.createWithPort(123);
        assert sil.lockFile.exists()==true;
        assert "123".equals(FileUtils.loadFileAsUtf8String(sil.lockFile).trim());
        

        sil.createWithPort(456);
        assert sil.lockFile.exists()==true;
        assert "456".equals(FileUtils.loadFileAsUtf8String(sil.lockFile).trim());
    }
}
@janakmulani
Copy link
Contributor

Thanks for reporting this issue.

I could reproduce your issue. We will fix it in a future release.

@vnashkev
Copy link
Author

vnashkev commented Jun 2, 2020

I have created pull request already: #646

@sclassen
Copy link
Contributor

sclassen commented Jun 5, 2020

fixed with #646 and #651

@sclassen sclassen closed this as completed Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants