php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58946 readFrame reports error-frames as "timeout"
Submitted: 2009-11-12 03:24 UTC Modified: 2009-11-14 17:10 UTC
From: pop3 at flachtaucher dot de Assigned: pierrick (profile)
Status: Closed Package: stomp (PECL)
PHP Version: 5.3.0 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pop3 at flachtaucher dot de
New email:
PHP Version: OS:

 

 [2009-11-12 03:24 UTC] pop3 at flachtaucher dot de
Description:
------------
Using ActiveMQ 5 as broker.

Do something that produces a STOMP error frame (e.g. unsubscribe for a queue I havent subscribed to).

Next readFrame will return false (same value as used for timeout). However it will not notify me that an error has occured. This makes it impossible for me to distinguish between "readFrame returned timeout" and "readFrame got an Error-Frame".

Proposed solution: Throw an Exception. 

Possible other solution: Document this behaviour.

Reproduce code:
---------------
<?php

try {
    $stomp = new Stomp('tcp://1.2.3.4:61613', 'user', 'password');
} catch(StompException $e) {
    die('Connection failed: ' . $e->getMessage()."\n");
    exit;
}
$stomp->unsubscribe('/queue/temp.foo');
$stomp->readFrame();

?>



here is my patch to make the module throw an exception:

--- stomp-0.3.1.orig/php_stomp.c        1970-01-01 10:14:21.000000000 +0100
+++ stomp-0.3.1/php_stomp.c     2009-11-12 09:08:42.000000000 +0100
@@ -845,6 +845,11 @@

         frame_destroy(res);
     } else {
+        if (stomp->error) {
+            STOMP_ERROR(stomp->errnum, stomp->error);
+        } else {
+            STOMP_ERROR(0, PHP_STOMP_ERR_UNKNOWN);
+        }
         RETURN_FALSE;
     }
 }


Expected result:
----------------
readFrame throws an exception or does something else that allows me to find out that I got an error-frame.

Actual result:
--------------
readFrame returns false.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-12 04:05 UTC] pop3 at flachtaucher dot de
Sorry my patch did not work. Here is a new one that works for me.

--- stomp-0.3.1.orig/stomp.c    1970-01-01 10:13:08.000000000 +0100
+++ stomp-0.3.1/stomp.c 2009-11-12 09:53:45.000000000 +0100
@@ -462,15 +462,6 @@
         f->body_length = stomp_read_buffer(stomp, &f->body);
     }

-    if (0 == strncmp("ERROR", f->command, sizeof("ERROR") - 1)) {
-        char *error_msg = NULL;
-        if (zend_hash_find(f->headers, "message", sizeof("message"), (void **)&error_msg) == SUCCESS) {
-            stomp_set_error(stomp, error_msg, 0);
-        }
-        frame_destroy(f);
-        return NULL;
-    }
-
     return f;
 }
 /* }}} */
--- stomp-0.3.1.orig/php_stomp.c        1970-01-01 10:14:21.000000000 +0100
+++ stomp-0.3.1/php_stomp.c     2009-11-12 09:57:56.000000000 +0100
@@ -817,6 +817,15 @@
             ulong pos;
             zend_hash_internal_pointer_reset(res->headers);

+            if (0 == strncmp("ERROR", res->command, sizeof("ERROR") - 1)) {
+                char *error_msg = NULL;
+                if (zend_hash_find(res->headers, "message", sizeof("message"), (void **)&error_msg) == SUCCESS) {
+                    STOMP_ERROR(0, error_msg);
+                    frame_destroy(res);
+                    RETURN_FALSE;
+                }
+            }
+
             while (zend_hash_get_current_key(res->headers, &key, &pos, 0) == HASH_KEY_IS_STRING) {
                 char *value = NULL;
                 if (zend_hash_get_current_data(res->headers, (void **)&value) == SUCCESS) {
 [2009-11-14 17:10 UTC] pierrick@php.net
This has been fixed in revision 290760. 

You can checkout the last version and test it again.

Thanks for reporting this issue.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC