How can I destroy or unset session?
Don't use low level session_destroy(), use the session manager instead:

\Drupal::service('session_manager')-&gt;destroy();


This will remove all session data and the user is logged out, if that's what you want. You still get a warning if there is no session, so you might want to check this first. 

A better solution might be to use the symfony Session object

$request = \Drupal::request();
$request-&gt;getSession()-&gt;clear();


if you have set the session data in the request object or

$_SESSION = [];


if you have used the deprecated $_SESSION superglobal.

Normally you don't destroy the session or clear all session data, because there might be other modules that also use session data. Simply remove session variables in the same place where you have set them.

$request = \Drupal::request();
$session = $request-&gt;getSession();
$session-&gt;set('mymodule.value', $value);

// remove later when you don't need the value anymore
$session-&gt;remove('mymodule.value');


When all modules removed their values the session is destroyed by Drupal automatically (for anonymous users).