1
Fork 0
photoview/api
Lajos Koszti 1f8664d7f8
fix transaction already commited error
I encountered with the following error:

> 2023/02/05 07:33:00 /app/scanner/face_detection/face_detector.go:92 sql: transaction has already been committed or rolled back
> [0.042ms] [rows:0] SELECT * FROM `media` WHERE `media`.`id` = 823 ORDER BY `media`.`id` LIMIT 1
> 2023/02/05 07:33:00 ERROR: Error detecting faces in image (/photos/Borzsony2017/DSC_0028.NEF): sql: transaction has already been committed or rolled back

It turned out it comes from the api/routes/photos.go

I found a very similar code in album_scanner.go.
The difference I saw was that while in the single photo request the
transaction passed to the `scanner_tasks.Tasks.BeforeProcessMedia` call,
in the album_scann.go the transaction created after this call and
created from the context which returned by `BeforeProcessMedia`.

Another difference was that in the `ProcessSingleMedia` call the
`AfterProcessMedia` call was called with the same - db transaction -
context, in the album_scanner it was called outside of the transaction.

I changed the logic by merging the two behavior:
Create the transaction from the context of `BeforeProcessMedia` and also
use the transaction context in the `AfterProcessMedia`.
After the change the error disappeared.

So to have it in a common place I extracted that logic into a function
and use for both the single photo request and in the album scanner.

I did not go more deeper to find out what's going on with the context
under the hood.
2023-02-05 09:05:05 +01:00
..
.vscode Properly merge SiteInfo in Apollo cache 2020-12-09 16:58:40 +01:00
data/models Start on face detection 2021-02-15 17:35:28 +01:00
database Fix Postgres exif flash migration error message 2022-02-13 16:57:20 +01:00
dataloader Batch exiftool runs + scanner package restructuring 2021-05-06 22:01:48 +02:00
graphql Add Turkish language 2022-12-02 15:32:49 +03:00
routes fix transaction already commited error 2023-02-05 09:05:05 +01:00
scanner fix transaction already commited error 2023-02-05 09:05:05 +01:00
server Make photoview work without providing the PHOTOVIEW_PUBLIC_ENDPOINT environment variable 2021-03-01 22:03:57 +01:00
test_utils Fix scanner queue tests 2022-03-28 18:43:00 +02:00
utils Make it compile again 2022-03-02 17:26:06 +01:00
example.env Completely remove PHOTOVIEW_PUBLIC_ENDPOINT 2021-03-01 22:11:58 +01:00
go.mod Add Basque language 2022-07-05 15:11:49 +02:00
go.sum Add Basque language 2022-07-05 15:11:49 +02:00
gqlgen.yml Sidebar: people section + album path 2021-10-19 23:28:23 +02:00
server.go Start on big scanner code refactoring 2022-02-14 23:57:45 +01:00