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

Can't remove file(which was read in reader) in afterStep listener on Windows [BATCH-2842] #772

Closed
spring-issuemaster opened this issue Sep 10, 2019 · 0 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Sep 10, 2019

Nikolay Tkachev opened BATCH-2842 and commented

When I run application on Windows mashine I experience following errror: 

2019-09-09 12:08:13.752 WARN 4028 --- [ main] c.b.m.b.RemovingListener : Failed to remove chunk 0b9a2623-b4c3-42b2-9acf-373a2d81007c.csv java.nio.file.FileSystemException: D:\chunk\1.csv: The process cannot access the file because it is being used by another process. at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92) at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103) at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108) at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:270) at java.base/sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:110) at java.base/java.nio.file.Files.deleteIfExists(Files.java:1180) at my.super.project.batch.RemovingListener.afterStep(RemovingListener.java:31) at my.super.project.batch.RemovingListener$$FastClassBySpringCGLIB$$e695a1e2.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:750) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) at my.super.project.batch.RemovingListener$$EnhancerBySpringCGLIB$$10d47ff9.afterStep(<generated>)

please take a look SO topic for more details: https://stackoverflow.com/questions/57851429/cant-remove-file-from-batch-listener-on-windows-the-process-cannot-access-the

 

Source code to reproduce: https://github.com/gredwhite/spring-batch-hello-world/tree/master/src/main/java/spring/boot/hello/process_cannot_access

 

 

I found that it happens because of IO stream close(

) happens after listener invocation(
exitStatus = exitStatus.and(getCompositeListener().afterStep(stepExecution));
) so file can't be removed until the IO stream is not closed.


Affects: 4.2.0.RC1

Issue Links:

  • BATCH-2098 FileItemReader should close the underlying reader before the step listener
    ("duplicates")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.