ilovejs / h2database

Automatically exported from code.google.com/p/h2database
0 stars 1 forks source link

a csvread failure keeps the file open on windows #588

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If I attempt to create a table using csvread, but it fails to import for one 
reason or another (in my case it's because I had mistakenly entered a string 
value in an integer column), then h2 keeps the original csv file open; I am not 
able to manipulate the file in windows by deleting it or renaming it etc., I 
have to first shutdown h2, then delete the file.

This is on windows 2008 r2, java 1.7, h2 ver 1.4.181.

Original issue reported on code.google.com by localde...@gmail.com on 15 Oct 2014 at 6:37

GoogleCodeExporter commented 9 years ago
You need to close the resultset for the file to be released.

Original comment by noelgrandin on 20 Oct 2014 at 6:38

GoogleCodeExporter commented 9 years ago
Please reopen this issue; this wasn't my code that was executing, it was the H2 
web browser console that I executed the command in. The bug is somewhere in H2, 
either the web console or the server that performs the csvread.

Original comment by localde...@gmail.com on 20 Oct 2014 at 5:58

GoogleCodeExporter commented 9 years ago
I see, you are using "create table ... as select ... from csvread" or "insert 
into ... select ... from csvread", right?

Looking at the code, it does look like the file is not closed when an exception 
occurs, but I currently don't see how to best solve this. As a workaround, I 
guess it's enough to call System.gc() a few times, but of course that's not 
really a solution.

Original comment by thomas.t...@gmail.com on 20 Oct 2014 at 6:24

GoogleCodeExporter commented 9 years ago
Issue 589 has been merged into this issue.

Original comment by thomas.t...@gmail.com on 20 Oct 2014 at 6:26

GoogleCodeExporter commented 9 years ago
Thanks for looking into this. Yes, I am using the "create table as select from 
csvread" syntax. I haven't seen the source, but is it not possible to close the 
file in the exception handler or the finally clause etc? I have none of my own 
code executing at that point, I can't call "system.gc()" since it's not my java 
process, it's the H2 java process.

Can you point me to the package / classname / line number if you still know 
roughly those details? Maybe I can write a small patch or something. We deal 
with a ton of generated csv files, not all of them are "clean" and so this 
problem is going to continue for us. 

Original comment by localde...@gmail.com on 21 Oct 2014 at 2:11

GoogleCodeExporter commented 9 years ago
Thomas, any updates on this? Can you point me in the general direction in terms 
of where I can find the issue in the source code?

Original comment by localde...@gmail.com on 29 Oct 2014 at 3:12

GoogleCodeExporter commented 9 years ago
A minimal test case would be great. I think the problem can occur if there is a 
problem reading the data, but also if there is a problem reading the header.

The problem is that "csvread" will open a ValueResultSet, which is then used to 
insert the data. That object is not closed. I'm also not sure on how to best 
solve this.

Original comment by thomas.t...@gmail.com on 15 Jan 2015 at 7:03