Port session ID fix from D7.

See https://www.drupal.org/node/2378699