As the title suggests, in some situations I step through the Magento 2 code, only for it to go to Magento\Framework\Session\SessionManager::writeClose(), thus calling session_write_close() and terminating the application immediately. The Call Stack is practically empty, so I can't see what is calling this. However if I insert a breakpoint and continue from there, it loads the website as if nothing has happened.
It only seems to occur on Magento 2 websites where it would suddenly terminate in such a fashion, however I'm not sure if it could be an issue with xdebug, Apache, or PHP-FPM.
Is there a reason why writeClose gets called, and how do I prevent this from occurring again whilst debugging?
If you require any additional information, then please leave a comment, and I shall update accordingly :-)
writeClose is called when you get an exception.
There is no way to prevent it.
The solution is to find where is the exception by debugging deeply.
When you debug then try to use F7 more instead of pressing F8 , you will go through all functionalities and get where the exception is. Then you see the root cause by exception messages.