Reputation: 871
The program i am trying to build, consumes files on a Windows file share using Camel 2.18.5 and other programs occasionally add/modify/delete files in the share folder.
Building a simple test route
from("file:///C:/Temp/from?readLock=changed&readLockCheckInterval=10000&readLockTimeout=0")
.routeId("SimpleFileRoute")
.to("file:/C:/Temp/to");
then placing a file, test.txt, in the from folder, waiting for the route to make a test.txt.camelLock file and then manually deleting test.txt before the readLockCheckInterval has passed, will cause the route to hang indefinitely without throwing an exception or processing any other files.
"changed" seems to be the only appropriate readLock for the situation.
Is there any way to make the route throw an exception, clean up the lock file and continue consuming files?
Edit: The stack trace of the thread that seems to be the route is this:
Daemon Thread [Camel (camel-1) thread #2 - file:///C:/Temp/from] (Suspended)
Thread.sleep(long) line: not available [native method]
FileChangedExclusiveReadLockStrategy.sleep() line: 104
FileChangedExclusiveReadLockStrategy.acquireExclusiveReadLock(GenericFileOperations<File>, GenericFile<File>, Exchange) line: 90
GenericFileRenameProcessStrategy<T>(GenericFileProcessStrategySupport<T>).begin(GenericFileOperations<T>, GenericFileEndpoint<T>, Exchange, GenericFile<T>) line: 64
GenericFileRenameProcessStrategy<T>.begin(GenericFileOperations<T>, GenericFileEndpoint<T>, Exchange, GenericFile<T>) line: 37
FileConsumer(GenericFileConsumer<T>).processExchange(Exchange) line: 362
FileConsumer(GenericFileConsumer<T>).processBatch(Queue<Object>) line: 223
FileConsumer(GenericFileConsumer<T>).poll() line: 187
FileConsumer(ScheduledPollConsumer).doRun() line: 174
FileConsumer(ScheduledPollConsumer).run() line: 101
Executors$RunnableAdapter<T>.call() line: 511
ScheduledThreadPoolExecutor$ScheduledFutureTask<V>(FutureTask<V>).runAndReset() line: 308
ScheduledThreadPoolExecutor$ScheduledFutureTask<V>.access$301(ScheduledThreadPoolExecutor$ScheduledFutureTask) line: 180
ScheduledThreadPoolExecutor$ScheduledFutureTask<V>.run() line: 294
RejectableScheduledThreadPoolExecutor(ThreadPoolExecutor).runWorker(ThreadPoolExecutor$Worker) line: 1142
ThreadPoolExecutor$Worker.run() line: 617
Thread.run() line: 745
Upvotes: 1
Views: 1153
Reputation: 55750
Okay so the issue is that you use readLockTimeout=0
which then prevents the read lock to timeout if a lock on the file cannot be granted, for whatever reason. You should not really do this (bad idea) so set it to a higher timeout value.
On the other hand we can also improve camel-core to check if the file still exists when it checks for changed and if the file doesnt exists then it can exit the check also.
I have logged a ticket about this: https://issues.apache.org/jira/browse/CAMEL-13025
Upvotes: 2