Skip to content
Snippets Groups Projects
Commit 3a9539e0 authored by Demian Katz's avatar Demian Katz
Browse files

Bug fix: never create row w/ session ID but no search data.

- There was a race condition where multiple parallel requests could end up with a fatal error caused by one process retrieving the partially created row generated by another process and trying to unserialize an empty string. By waiting to write the session ID to the database until we also have the data available, we can avoid this problem.
parent 4aa60580
No related merge requests found
...@@ -181,15 +181,16 @@ class Search extends Gateway ...@@ -181,15 +181,16 @@ class Search extends Gateway
// If we got this far, we didn't find a saved duplicate, so we should // If we got this far, we didn't find a saved duplicate, so we should
// save the new search: // save the new search:
$data = [ $this->insert(['created' => date('Y-m-d')]);
'session_id' => $sessionId,
'created' => date('Y-m-d'),
];
$this->insert($data);
$row = $this->getRowById($this->getLastInsertValue()); $row = $this->getRowById($this->getLastInsertValue());
// Chicken and egg... We didn't know the id before insert // Chicken and egg... We didn't know the id before insert
$newSearch->updateSaveStatus($row); $newSearch->updateSaveStatus($row);
// Don't set session ID until this stage, because we don't want to risk
// ever having a row that's associated with a session but which has no
// search object data attached to it; this could cause problems!
$row->session_id = $sessionId;
$row->search_object = serialize(new minSO($newSearch)); $row->search_object = serialize(new minSO($newSearch));
$row->save(); $row->save();
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment