WKWebView sometimes loses the session cookies variable

I have a Ruby on Rails backend web application. I use iOS application as a web client (WKWebView) written in swift. The authentication token is stored as a session cookies variable on the backend:

session['token'] = generate_token

The problem is that accidentally this session variable is lost and the flow is redirected to login page. The WKWebView is not closed, just used to process HTTP requests. I'm not able to figure out, why this accidentally happens. It seems like a WKWebView bug, because in Safari this problem has been never happened.