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

Locker_JavaNio.lock() doesn't wrap I/O exceptions #692

Closed
trancexpress opened this issue Oct 30, 2024 · 1 comment · Fixed by #693
Closed

Locker_JavaNio.lock() doesn't wrap I/O exceptions #692

trancexpress opened this issue Oct 30, 2024 · 1 comment · Fixed by #693

Comments

@trancexpress
Copy link
Contributor

We have this exception printed on standard error:

Caused by: java.io.IOException: An error occurred while locking file "...": "No locks available". A common reason is that the file system or Runtime Environment does not support file locking for that location. Please choose a different location, or disable file locking by passing "-Dosgi.locking=none" as a VM argument.
	at org.eclipse.osgi.internal.location.Locker_JavaNio.lock(Locker_JavaNio.java:53)
	at org.eclipse.osgi.storagemanager.StorageManager.lock(StorageManager.java:403)
	at org.eclipse.osgi.storagemanager.StorageManager.open(StorageManager.java:716)
	at org.eclipse.osgi.storage.Storage.getChildStorageManager(Storage.java:2241)
	at org.eclipse.osgi.storage.Storage.getInfoInputStream(Storage.java:2258)
	at org.eclipse.osgi.storage.Storage.<init>(Storage.java:253)
	at org.eclipse.osgi.storage.Storage.createStorage(Storage.java:181)
	at org.eclipse.osgi.internal.framework.EquinoxContainer.<init>(EquinoxContainer.java:108)

While the error message tries to explain what went wrong, I would still like to know what the actual occurred IOException is. It should get wrapped, not just used to extend the error message:

	@Override
	public synchronized boolean lock() throws IOException {
		raFile = new RandomAccessFile(lockFile, "rw"); //$NON-NLS-1$
		try {
			/*
			 * fix for bug http://bugs.sun.com/view_bug.do?bug_id=6628575 and
			 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=44735#c17
			 */
			fileLock = raFile.getChannel().tryLock(0, 1, false);
		} catch (IOException ioe) {
			// print exception if debugging
			if (debug)
				System.out.println(NLS.bind(Msg.location_cannotLock, lockFile));
			// produce a more specific message for clients
			String specificMessage = NLS.bind(Msg.location_cannotLockNIO, new Object[] {lockFile, ioe.getMessage(), "\"-D" + LocationHelper.PROP_OSGI_LOCKING + "=none\""}); //$NON-NLS-1$ //$NON-NLS-2$
			throw new IOException(specificMessage);
		} catch (OverlappingFileLockException e) {
			// handle it as null result
			fileLock = null;
		} finally {
			if (fileLock != null)
				return true;
			raFile.close();
			raFile = null;
		}
		return false;
	}

I essentially have to grep OpenJDK code to find where "No locks available" is coming from.

@tjwatson
Copy link
Contributor

I agree, we should set the cause of the thrown new IOException with the original one caught.

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

Successfully merging a pull request may close this issue.

2 participants