Magento 2.2.1 bug on the frontend checkout page: «session_destroy(): Session object destruction failed in Magento/Framework/Session/SessionManager.php on line 513»

Exception #0 (Exception): Warning: session_destroy(): Session object destruction failed in lib\internal\Magento\Framework\Session\SessionManager.php on line 513
#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(2, 'session_destroy...', 'C:\\work\\mage2.p...', 513, Array)
#1 lib\internal\Magento\Framework\Session\SessionManager.php(513): session_destroy()
#2 app\code\Magento\Customer\Model\Session.php(564): Magento\Framework\Session\SessionManager->regenerateId()
#3 generated\code\Magento\Customer\Model\Session\Interceptor.php(310): Magento\Customer\Model\Session->regenerateId()
#4 app\code\Magento\Checkout\Controller\Index\Index.php(35): Magento\Customer\Model\Session\Interceptor->regenerateId()
#5 lib\internal\Magento\Framework\Interception\Interceptor.php(58): Magento\Checkout\Controller\Index\Index->execute()
#6 lib\internal\Magento\Framework\Interception\Interceptor.php(138): Magento\Checkout\Controller\Index\Index\Interceptor->___callParent('execute', Array)
#7 lib\internal\Magento\Framework\Interception\Interceptor.php(153): Magento\Checkout\Controller\Index\Index\Interceptor->Magento\Framework\Interception\{closure}()
#8 generated\code\Magento\Checkout\Controller\Index\Index\Interceptor.php(26): Magento\Checkout\Controller\Index\Index\Interceptor->___callPlugins('execute', Array, Array)
#9 lib\internal\Magento\Framework\App\Action\Action.php(107): Magento\Checkout\Controller\Index\Index\Interceptor->execute()
#10 app\code\Magento\Checkout\Controller\Onepage.php(161): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#11 lib\internal\Magento\Framework\Interception\Interceptor.php(58): Magento\Checkout\Controller\Onepage->dispatch(Object(Magento\Framework\App\Request\Http))
#12 lib\internal\Magento\Framework\Interception\Interceptor.php(138): Magento\Checkout\Controller\Index\Index\Interceptor->___callParent('dispatch', Array)
#13 lib\internal\Magento\Framework\Interception\Interceptor.php(153): Magento\Checkout\Controller\Index\Index\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#14 generated\code\Magento\Checkout\Controller\Index\Index\Interceptor.php(39): Magento\Checkout\Controller\Index\Index\Interceptor->___callPlugins('dispatch', Array, Array)
#15 lib\internal\Magento\Framework\App\FrontController.php(55): Magento\Checkout\Controller\Index\Index\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#16 lib\internal\Magento\Framework\Interception\Interceptor.php(58): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#17 lib\internal\Magento\Framework\Interception\Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#18 app\code\Magento\Store\App\FrontController\Plugin\RequestPreprocessor.php(94): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#19 lib\internal\Magento\Framework\Interception\Interceptor.php(135): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#20 app\code\Magento\PageCache\Model\App\FrontController\BuiltinPlugin.php(73): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#21 lib\internal\Magento\Framework\Interception\Interceptor.php(135): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#22 lib\internal\Magento\Framework\Interception\Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#23 generated\code\Magento\Framework\App\FrontController\Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, NULL)
#24 lib\internal\Magento\Framework\App\Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#25 lib\internal\Magento\Framework\App\Bootstrap.php(256): Magento\Framework\App\Http->launch()
#26 index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#27 {main}

The erroneous core is an usual Magento 2 “friday commit”: Magento 2 team is worried about reporting “my weekly job is done” on Fridays, and commits a lot of bugs every Friday:

https://github.com/magento/magento2/commit/d2d82aca595f393cee43a46dc88520428fe4d4de#diff-b4aa30666c05e391240357a7a435a7a8

It has changed the Magento\Framework\Session\SessionManager::regenerateId() method.

Before:

https://github.com/magento/magento2/blob/2d8323a7/lib/internal/Magento/Framework/Session/SessionManager.php#L496-L517

After:

https://github.com/magento/magento2/blob/d2d82aca595f393cee43a46dc88520428fe4d4de/lib/internal/Magento/Framework/Session/SessionManager.php#L496-L526

A workaround

Reverse the Magento\Framework\Session\SessionManager::regenerateId() method to the previous state.