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

Diesel crashes but should return db error #1119

Closed
Boscop opened this Issue Aug 18, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@Boscop

Boscop commented Aug 18, 2017

In sqlite FTS, searching for a string that is empty or contains only punctuation returns an error in the sqlite3 cli like so:

sqlite> select * from midi_files where id in (select rowid from midi_files_fts('!'));
Error: fts5: syntax error near "!"

Btw, it works when the string contains alphanumeric chars:

sqlite> select * from midi_files where id in (select rowid from midi_files_fts('colou*'));
74964|Bud\Colour_Of_My_Love-Celine.Dion.mid|22996
78136|Siem\sash_feat_dr_alban_-_colour_the_world.mid|55853
78442|Thai\darius_colourblind.mid|47976

When I use this code

let query = sql::<midi_files::SqlType>("select * from midi_files where id in (select rowid from midi_files_fts(?))").bind::<Text, _>(s);
query.get_results::<Self>(&*db::conn())?

if the string is empty or only contains punctuation, instead of returning a db error, diesel crashes:

thread 'main' panicked at 'SQL error or missing database', C:\Users\me\.cargo\re
gistry\src\github.com-1ecc6299db9ec823\diesel-0.15.2\src\sqlite\connection\stmt.
rs:126:21
stack backtrace:
thread 'ui' panicked at 'cannot access stderr during shutdown', error: process d

I think diesel should return an error instead of crashing.

@killercup

This comment has been minimized.

Member

killercup commented Aug 19, 2017

Thanks for the report! The error you quoted comes from this function:

fn step(&mut self) -> Option<SqliteRow> {
match unsafe { ffi::sqlite3_step(self.inner_statement) } {
ffi::SQLITE_DONE => None,
ffi::SQLITE_ROW => Some(SqliteRow::new(self.inner_statement)),
error => panic!("{}", super::error_message(error)),
}
}

I agree, panic does see very harsh here and I too would expect a Result here. I twas introduced in 17a3034, the first commit to add SQLite support. Is there any scenario where the sqlite connection is essentially irreparably broken when such an error occurs? I.e., can we always return Err in the last match arm?

@Boscop

This comment has been minimized.

Boscop commented Aug 19, 2017

I'm not an sqlite expert but I tested it in the REPL and I don't see a reason why the connection wouldn't be perfectly usable afterwards.

@sgrif

This comment has been minimized.

Member

sgrif commented Sep 5, 2017

The main question isn't whether the connection is useable, but whether the statement itself is useable. I suspect we need to remove that statement from the cache if an error occurs here.

@sgrif

This comment has been minimized.

Member

sgrif commented Jan 17, 2018

This no longer panics as of 1.0.0-rc1. I still have concerns about whether the statement cache is poisoned by this case or not. If anyone is able to create a repro script that shows a poisoned prepared statement from this, I would appreciate an issue report.

@sgrif sgrif closed this Jan 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment