You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Johannes Scharf (JIRA)" <ji...@apache.org> on 2010/01/08 15:12:54 UTC
[jira] Issue Comment Edited: (VFS-293) FtpFileSystem causes
deadlock
[ https://issues.apache.org/jira/browse/VFS-293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12798020#action_12798020 ]
Johannes Scharf edited comment on VFS-293 at 1/8/10 2:12 PM:
-------------------------------------------------------------
I've found a possible solution for this bug.
Simply synchronize the getClient and putClient methods themselves on "this" and remove the synchronized block inside the methods which synchronzes on "idleClientSync".
{code:java}
public synchronized FtpClient getClient() throws FileSystemException {
if (idleClient == null || !idleClient.isConnected()) {
if (log.isDebugEnabled()) {
log.debug("getClient(): Returning new FtpClient...");
}
FtpClient ftpClient = new FtpClientWrapper(
(GenericFileName) getRoot().getName(),
getFileSystemOptions());
return ftpClient;
} else {
if (log.isDebugEnabled()) {
log.debug("getClient(): Returning idle FtpClient...");
}
final FtpClient client = idleClient;
idleClient = null;
return client;
}
}
public synchronized void putClient(final FtpClient client) {
if (idleClient == null) {
if (log.isDebugEnabled()) {
log.debug("Pooling used FtpClient...");
}
// Hang on to client for later
idleClient = client;
} else {
if (log.isDebugEnabled()) {
log.debug("Disposing used FtpClient...");
}
// Close the client
closeConnection(client);
}
}
{code}
was (Author: scharfj):
I've found a possible solution for this bug.
Simply synchronize the getClient and putClient methods themselves on "this" and remove the synchronized block inside the methods which synchronzes on "idleClientSync".
{code:java}
@Override
public synchronized FtpClient getClient() throws FileSystemException {
if (idleClient == null || !idleClient.isConnected()) {
if (log.isDebugEnabled()) {
log.debug("getClient(): Returning new FtpClient...");
}
FtpClient ftpClient = new FtpClientWrapper(
(GenericFileName) getRoot().getName(),
getFileSystemOptions());
return ftpClient;
} else {
if (log.isDebugEnabled()) {
log.debug("getClient(): Returning idle FtpClient...");
}
final FtpClient client = idleClient;
idleClient = null;
return client;
}
}
public synchronized void putClient(final FtpClient client) {
if (idleClient == null) {
if (log.isDebugEnabled()) {
log.debug("Pooling used FtpClient...");
}
// Hang on to client for later
idleClient = client;
} else {
if (log.isDebugEnabled()) {
log.debug("Disposing used FtpClient...");
}
// Close the client
closeConnection(client);
}
}
{code}
> FtpFileSystem causes deadlock
> -----------------------------
>
> Key: VFS-293
> URL: https://issues.apache.org/jira/browse/VFS-293
> Project: Commons VFS
> Issue Type: Bug
> Affects Versions: 1.0
> Reporter: Johannes Scharf
>
> I use Commons VFS to access FTP from multiple threads. In each thread I create directories and copy files on the FTP server.
> Nearly everytime when i run the program a deadlock occurs which causes all threads to hang. I've created a stacktrace with "jstack" which clearly shows where the deadlock is happening.
> Stacktrace:
> {noformat}
> Found one Java-level deadlock:
> =============================
> "pool-1-thread-5":
> waiting to lock monitor 0x030813b4 (object 0x22f972e8, a org.apache.commons.vfs.provider.ftp.FtpFileSystem),
> which is held by "pool-1-thread-2"
> "pool-1-thread-2":
> waiting to lock monitor 0x03082c7c (object 0x22f999e0, a java.lang.Object),
> which is held by "pool-1-thread-4"
> "pool-1-thread-4":
> waiting to lock monitor 0x030813b4 (object 0x22f972e8, a org.apache.commons.vfs.provider.ftp.FtpFileSystem),
> which is held by "pool-1-thread-2"
> Java stack information for the threads listed above:
> ===================================================
> "pool-1-thread-5":
> at org.apache.commons.vfs.provider.AbstractFileSystem.streamOpened(AbstractFileSystem.java:569)
> - waiting to lock <0x22f972e8> (a org.apache.commons.vfs.provider.ftp.FtpFileSystem)
> at org.apache.commons.vfs.provider.DefaultFileContent.streamOpened(DefaultFileContent.java:92)
> at org.apache.commons.vfs.provider.DefaultFileContent.getOutputStream(DefaultFileContent.java:377)
> at at.js.jtransporter.transporter.VFSTransporter.createFile(VFSTransporter.java:119)
> at at.js.jtransporter.worker.resource.ResourceWorker.createFile(ResourceWorker.java:80)
> at at.js.jtransporter.worker.resource.ResourceWorker.processJob(ResourceWorker.java:51)
> at at.js.jtransporter.worker.AbstractRunnableWorker.run(AbstractRunnableWorker.java:82)
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
> at java.lang.Thread.run(Thread.java:619)
> "pool-1-thread-2":
> at org.apache.commons.vfs.provider.ftp.FtpFileSystem.putClient(FtpFileSystem.java:137)
> - waiting to lock <0x22f999e0> (a java.lang.Object)
> at org.apache.commons.vfs.provider.ftp.FtpFileObject.doGetChildren(FtpFileObject.java:158)
> at org.apache.commons.vfs.provider.ftp.FtpFileObject.getChildFile(FtpFileObject.java:103)
> at org.apache.commons.vfs.provider.ftp.FtpFileObject.getInfo(FtpFileObject.java:181)
> at org.apache.commons.vfs.provider.ftp.FtpFileObject.refresh(FtpFileObject.java:208)
> at org.apache.commons.vfs.provider.AbstractFileSystem.resolveFile(AbstractFileSystem.java:319)
> - locked <0x22f972e8> (a org.apache.commons.vfs.provider.ftp.FtpFileSystem)
> at org.apache.commons.vfs.provider.AbstractFileSystem.resolveFile(AbstractFileSystem.java:267)
> - locked <0x22f972e8> (a org.apache.commons.vfs.provider.ftp.FtpFileSystem)
> at org.apache.commons.vfs.provider.AbstractFileObject.getParent(AbstractFileObject.java:512)
> - locked <0x22f972e8> (a org.apache.commons.vfs.provider.ftp.FtpFileSystem)
> at org.apache.commons.vfs.provider.ftp.FtpFileObject.getInfo(FtpFileObject.java:177)
> at org.apache.commons.vfs.provider.ftp.FtpFileObject.refresh(FtpFileObject.java:208)
> at org.apache.commons.vfs.provider.AbstractFileSystem.resolveFile(AbstractFileSystem.java:319)
> - locked <0x22f972e8> (a org.apache.commons.vfs.provider.ftp.FtpFileSystem)
> at org.apache.commons.vfs.provider.AbstractFileSystem.resolveFile(AbstractFileSystem.java:267)
> - locked <0x22f972e8> (a org.apache.commons.vfs.provider.ftp.FtpFileSystem)
> at org.apache.commons.vfs.provider.AbstractFileObject.resolveFile(AbstractFileObject.java:670)
> at at.js.jtransporter.transporter.VFSTransporter.createFile(VFSTransporter.java:118)
> at at.js.jtransporter.worker.resource.ResourceWorker.createFile(ResourceWorker.java:80)
> at at.js.jtransporter.worker.resource.ResourceWorker.processJob(ResourceWorker.java:51)
> at at.js.jtransporter.worker.AbstractRunnableWorker.run(AbstractRunnableWorker.java:82)
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
> at java.lang.Thread.run(Thread.java:619)
> "pool-1-thread-4":
> at org.apache.commons.vfs.provider.AbstractFileSystem.resolveFile(AbstractFileSystem.java:267)
> - waiting to lock <0x22f972e8> (a org.apache.commons.vfs.provider.ftp.FtpFileSystem)
> at org.apache.commons.vfs.provider.AbstractFileSystem.getRoot(AbstractFileSystem.java:242)
> at org.apache.commons.vfs.provider.ftp.FtpFileSystem.getClient(FtpFileSystem.java:108)
> - locked <0x22f999e0> (a java.lang.Object)
> at org.apache.commons.vfs.provider.ftp.FtpFileObject.doGetOutputStream(FtpFileObject.java:490)
> at org.apache.commons.vfs.provider.AbstractFileObject.getOutputStream(AbstractFileObject.java:1219)
> at org.apache.commons.vfs.provider.DefaultFileContent.getOutputStream(DefaultFileContent.java:373)
> at at.js.jtransporter.transporter.VFSTransporter.createFile(VFSTransporter.java:119)
> at at.js.jtransporter.worker.resource.ResourceWorker.createFile(ResourceWorker.java:80)
> at at.js.jtransporter.worker.resource.ResourceWorker.processJob(ResourceWorker.java:51)
> at at.js.jtransporter.worker.AbstractRunnableWorker.run(AbstractRunnableWorker.java:82)
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
> at java.lang.Thread.run(Thread.java:619)
> Found 1 deadlock.
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.