-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Database exception using DbSession #13212
Comments
I think |
looks like it. If session_regenerate_id fails to generate an ID, its no use to update the DB with it. |
Should the old session row be deleted in case the new ID can not be generated? For something like to prevent loosing the old data in race condition case? I've tested |
Same issue with Redis session implementation. |
@bizley I guess there is no need to delete session row. |
@yanhuixie it's a bit different, |
@andrewnester can you confirm that old row is deleted or updated later on? Because if not there is the risk of DB storage overfill. |
@bizley thanks for reasonable question! In this case |
I still have issue with it. Here is what I have in log:
One of the solution is to check if there is any duplicates in the database, before inserting or updating db. But I'm not sure this solution is the correct ones. |
I would like to reopen this issue as I now (after 2.0.13 upgrade) get a lot of errors like this. I've proposed a PR. |
ATM the only proper way to fix it (IMO) is #13879. |
We can catch exception and retry? |
Yes, we can but it's like a hotfix. Proper solution is #13879 |
Implementation of upsert looks really complicated to me, it probably will be source of new bugs and may make situation even worse. I prefer use this hotfix in patch release and switch to upsert in 2.0.14. |
Makes sense. Let's do try-catch for 2.0.13.1 and replace implementation with upsert when it's ready. Would you help with a pull request? |
Yes, a hotfix in 2.0.13.1 sounds reasonable. WITH
"EXCLUDED" ("email", "name", "address", "bool_status", "profile_id") AS (VALUES (:qp0, :qp1, :qp2, :qp3, CAST(NULL AS int4))),
"upsert" AS (UPDATE "customer" SET "email"="EXCLUDED"."email", "name"="EXCLUDED"."name", "address"="EXCLUDED"."address", "bool_status"="EXCLUDED"."bool_status", "profile_id"="EXCLUDED"."profile_id" FROM "EXCLUDED" WHERE (("customer"."email"="EXCLUDED"."email")) RETURNING "customer".*)
INSERT INTO "customer" ("email", "name", "address", "bool_status", "profile_id") SELECT "email", "name", "address", "bool_status", "profile_id" FROM "EXCLUDED" WHERE NOT EXISTS (SELECT 1 FROM "upsert" WHERE (("upsert"."email"="EXCLUDED"."email"))) So it will definitely require testing (in addition to unit tests). |
Wow, ↑ isn't how it is usually done. |
I thought about resubmitting an MR with try/catch and ignore if there is a duplicate key. There is no need to retry when we've hit the race condition as session data has just been saved. However, I'm not sure how to verify it's a duplicate key in DBMS-independent way. For MySQL the PDO error code is 1062 but I couldn't find the ones for MSSQL, Postgres and SQLite. |
@sergeymakinen https://github.com/symfony/symfony/pull/10652/files may give you some hints (related problem). |
@samdark It was 04 or 05 am and I was not clear. :) The code was for a generic upsert implementation where |
@samdark While the sample code is pretty logical when working with sessions. But did they miss pgsql? I would wonder why. 👹 |
Tests are quite interesting as well: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php |
This means that the hardest part (pgsql <9.5) is done. Other implementations are trivial. MySQL’s and MSSQL’s upserts are also completed. |
your sessionid is 1? |
Oh. Original exception is even "better". ID is 0 o_0 |
@samdark if there is no progress on this, I can try to pick it and create a PR based on Symphony's solution. So that we can get it out in 2.0.13.2 hopefully? |
@sergeymakinen is trying hard to finish upserts support. |
Sorry, for confusions, I've found out that my problem was linked with incorrect type of Mysql field |
@puku thanks for letting us know. We still want upserts for sessions though so I'm leaving it open for now. |
See #11401 |
What steps will reproduce the problem?
When I'm trying to login on the website, from time to time I'm receiving an error message.
After reloading of the page everything is ok.
YII_DEBUG
is enabled,YII_ENV_DEV
is set to true.Maybe this issue is linked with this one
Stackoverflow question
What do you get instead?
Additional info
The text was updated successfully, but these errors were encountered: