-
-
Notifications
You must be signed in to change notification settings - Fork 495
Closed
Description
Ironically this function has a bug:
rust-postgres/postgres/src/transaction.rs
Lines 246 to 248 in 12546ec
pub fn transaction<'a>(&'a self) -> Result<Transaction<'a>> { | |
self.savepoint("sp") | |
} |
Basically it should not reuse the savepoint name sp
.
If you do something like:
BEGIN;
INSERT INTO t VALUES (1);
SAVEPOINT sp;
INSERT INTO t VALUES (2);
SAVEPOINT sp;
INSERT INTO t VALUES (3);
ROLLBACK TO sp;
ROLLBACK TO sp;
COMMIT;
then the table will contain 1 and 2!
And while you probably won't run into this in most code,
it can happen much easier if you have code generic over
GenericConnection
which uses a transaction.
Possible fixes:
- always generate a name including the
current depth (format!("sp{}", self.depth)
) - only generate a name if the depth > 1
(assuming that it starts with 0 on first trans without savepoint, 1 on second etc.)
When we are at it we might want to change savepoint
to accept <S: Into<String>>
instead of &str
.
I will see if I can make a pull request, but I won't
have time for it before the weekend.
Metadata
Metadata
Assignees
Labels
No labels