diff --git a/framework/web/Session.php b/framework/web/Session.php
index <HASH>..<HASH> 100644
--- a/framework/web/Session.php
+++ b/framework/web/Session.php
@@ -96,7 +96,9 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
     public function init()
     {
         parent::init();
-        register_shutdown_function([$this, 'close']);
+        if ($this->getIsActive()) {
+            Yii::warning("Session is already started", __METHOD__);
+        }
     }
 
     /**
@@ -129,6 +131,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
         if ($this->getIsActive()) {
             Yii::info('Session started', __METHOD__);
             $this->updateFlashCounters();
+            register_shutdown_function([$this, 'close']);
         } else {
             $error = error_get_last();
             $message = isset($error['message']) ? $error['message'] : 'Failed to start session.';
1. Added init() warning to session component
2. register_shutdown_function() for Session::close now only calls after successful session open