Session not setting in some instances #3

Closed
UndefinedOffset opened this Issue Apr 5, 2014 · 3 comments

Comments

1 participant
@UndefinedOffset
Owner

UndefinedOffset commented Apr 5, 2014

For some reason in some instances the session cookie/id is not being relayed in the headers for the client API. Causing all subsequent requests to the server to trigger a session expired notice in the client. On most servers it works fine on some others it does not, smells like a issue specific to the server but it requires experimentation on a server with the problem.

@UndefinedOffset

This comment has been minimized.

Show comment
Hide comment
@UndefinedOffset

UndefinedOffset Apr 5, 2014

Owner

Current hunch is that this patch may fix the issue, but needs testing on a server that is having the problem.

diff --git a/code/classes/CodeBankAMFServer.php b/code/classes/CodeBankAMFServer.php
index 7b013f4..1e8dd19 100644
--- a/code/classes/CodeBankAMFServer.php
+++ b/code/classes/CodeBankAMFServer.php
@@ -80,7 +80,15 @@

         return $return;
     }
-
+    
+    /**
+     * Whether of not the server is using sessions
+     * @return bool
+     */
+    public function isSession() {
+        return ($this->_session || array_key_exists($this->_sessionName, $_COOKIE));
+    }
+    
     /**
      * (Re)Build the dispatch table. The dispatch table consists of a an array of method name => Zend_Server_Reflection_Function_Abstract pairs
      * @return void
diff --git a/code/control/CodeBankClientAPI.php b/code/control/CodeBankClientAPI.php
index 7704a8c..91e1ead 100644
--- a/code/control/CodeBankClientAPI.php
+++ b/code/control/CodeBankClientAPI.php
@@ -17,6 +17,10 @@
      * Handles all amf requests
      */
     public function index() {
+       //Ensure the session is started
+       Session::start();
+       
+       
         //Start the server
         $server=new CodeBankAMFServer();

@@ -35,15 +39,9 @@

         $server->setProduction(!Director::isDev()); //Server debug, bind to opposite of Director::isDev()

-        //Start the response
-        $response=$server->handle();

-        //Output
-        echo $response;
-        
-        //Save session and exit
-        Session::save();
-        exit;
+        //Handle and return
+        return $server->handle();
     }

     /**
Owner

UndefinedOffset commented Apr 5, 2014

Current hunch is that this patch may fix the issue, but needs testing on a server that is having the problem.

diff --git a/code/classes/CodeBankAMFServer.php b/code/classes/CodeBankAMFServer.php
index 7b013f4..1e8dd19 100644
--- a/code/classes/CodeBankAMFServer.php
+++ b/code/classes/CodeBankAMFServer.php
@@ -80,7 +80,15 @@

         return $return;
     }
-
+    
+    /**
+     * Whether of not the server is using sessions
+     * @return bool
+     */
+    public function isSession() {
+        return ($this->_session || array_key_exists($this->_sessionName, $_COOKIE));
+    }
+    
     /**
      * (Re)Build the dispatch table. The dispatch table consists of a an array of method name => Zend_Server_Reflection_Function_Abstract pairs
      * @return void
diff --git a/code/control/CodeBankClientAPI.php b/code/control/CodeBankClientAPI.php
index 7704a8c..91e1ead 100644
--- a/code/control/CodeBankClientAPI.php
+++ b/code/control/CodeBankClientAPI.php
@@ -17,6 +17,10 @@
      * Handles all amf requests
      */
     public function index() {
+       //Ensure the session is started
+       Session::start();
+       
+       
         //Start the server
         $server=new CodeBankAMFServer();

@@ -35,15 +39,9 @@

         $server->setProduction(!Director::isDev()); //Server debug, bind to opposite of Director::isDev()

-        //Start the response
-        $response=$server->handle();

-        //Output
-        echo $response;
-        
-        //Save session and exit
-        Session::save();
-        exit;
+        //Handle and return
+        return $server->handle();
     }

     /**

@UndefinedOffset UndefinedOffset removed the bug label Apr 13, 2014

@UndefinedOffset

This comment has been minimized.

Show comment
Hide comment
@UndefinedOffset

UndefinedOffset Apr 13, 2014

Owner

Headers returned by server when logging in:

HTTP/1.1 200 OK
Date: Sun, 13 Apr 2014 16:25:17 GMT
Server: Apache mod_fcgid/2.3.*
X-Powered-By: PHP/5.4.*
Cache-Control: no-cache, must-revalidate
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Set-Cookie: alc_enc=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/
Set-Cookie: alc_enc=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/
Keep-Alive: timeout=5
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/x-amf

No session cookie is sent, and the alc_enc cookie is being set to deleted and expired.

Owner

UndefinedOffset commented Apr 13, 2014

Headers returned by server when logging in:

HTTP/1.1 200 OK
Date: Sun, 13 Apr 2014 16:25:17 GMT
Server: Apache mod_fcgid/2.3.*
X-Powered-By: PHP/5.4.*
Cache-Control: no-cache, must-revalidate
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Set-Cookie: alc_enc=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/
Set-Cookie: alc_enc=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/
Keep-Alive: timeout=5
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/x-amf

No session cookie is sent, and the alc_enc cookie is being set to deleted and expired.

@UndefinedOffset UndefinedOffset added the bug label Apr 13, 2014

@UndefinedOffset

This comment has been minimized.

Show comment
Hide comment
@UndefinedOffset

UndefinedOffset Apr 13, 2014

Owner

The issue seems to be addressed, fix is incoming shortly

Owner

UndefinedOffset commented Apr 13, 2014

The issue seems to be addressed, fix is incoming shortly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment