Bug 1136418

Summary: QMF Session name to contain user ID
Product: Red Hat Enterprise MRG Reporter: Pavel Moravec <pmoravec>
Component: qpid-cppAssignee: Pavel Moravec <pmoravec>
Status: CLOSED ERRATA QA Contact: Otavio Piske <opiske>
Severity: medium Docs Contact:
Priority: medium    
Version: 3.0CC: freznice, jross, opiske, pematous, zkraus
Target Milestone: 3.2   
Target Release: ---   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: qpid-cpp-0.32-1 Doc Type: Bug Fix
Doc Text:
It was discovered that QMF could not handle sessions of the same name attached in parallel by different users because it stored session objects by their name: unique per user only. The fix implements a session ID for QMF in `SessionState.cpp`, by requesting `std::string name(getId().str());` instead of `std::string name(getId().getName());`.
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-10-08 13:09:10 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Pavel Moravec 2014-09-02 14:11:54 UTC
Description of problem:
AMQP 0-10 allows sessions of the same name attached in parallel by different users. Broker allows that, but QMF can't cope with it properly as it stores session object by its name - that is unique per one user only.

Therefore, QMF does not track all sessions, subscriptions (maybe something else) in those cases.

It is required to have unique session ID for QMF. Either having user ID as part of the session ID, or use pointer to the session object like AMQP 1.0 implementation uses.


Version-Release number of selected component (if applicable):
any (0.18-30, 0.22-48)


How reproducible:
100%


Steps to Reproduce:
1) Have usera:usera and userb:userb credentials for qpid broker
2) Compile below program:

#include <cstdlib>
#include <iostream>

#include <sstream>

#include <qpid/messaging/Address.h>
#include <qpid/messaging/Connection.h>
#include <qpid/messaging/Message.h>
#include <qpid/messaging/Sender.h>
#include <qpid/messaging/Receiver.h>
#include <qpid/messaging/Session.h>


using namespace qpid::messaging;
using namespace qpid::types;

using std::stringstream;
using std::string;

int main(int argc, char** argv) {
    const char* session_name = argc>1 ? argv[1] : "session_name";
    const char* connectionOptions = argc>2 ? argv[2] : "{username:guest, password:guest}";
    const char* address = argc>3 ? argv[3] : "myQueue; {create:always}";
    Connection connection("localhost:5672", connectionOptions);
    try {
        connection.open();
        Session session = connection.createSession(session_name);
	Receiver receiver = session.createReceiver(address);
	receiver.fetch();

        connection.close();
        return 0;
    } catch(const std::exception& error) {
        std::cout << error.what() << std::endl;
        connection.close();
    }
    return 1;
}


3) ./session_attach_given_name aaa "{username:usera, password:usera}" &
4) ./session_attach_given_name aaa "{username:userb, password:userb}" &
5) grep errors in qpidd logs
6) check subscriptions (qpid-stat -u) and sessions (qpid-tool -> list session) that QMF is aware of


Actual results:
5) qpid prints errors:
2014-09-02 16:07:04 [Management] error Detected two management objects with the same identifier: 0-51-1--17(org.apache.qpid.broker:subscription:org.apache.qpid.broker:session:aaa,org.apache.qpid.broker:queue:myQueue,myQueue)
2014-09-02 16:07:04 [Management] error Detected two management objects with the same identifier: 0-51-1--14(org.apache.qpid.broker:session:aaa)

6) there is just 1 subscription for "myQueue" queue (while both programs create one) and just 1 session named "aaa".


Expected results:
no error, 2 subscriptions, 2 sessions


Additional info:

Comment 1 Pavel Moravec 2014-09-07 12:40:58 UTC
Trivial patch:

Index: cpp/src/qpid/broker/SessionState.cpp
===================================================================
--- cpp/src/qpid/broker/SessionState.cpp	(revision 1622984)
+++ cpp/src/qpid/broker/SessionState.cpp	(working copy)
@@ -69,7 +69,7 @@
     if (parent != 0) {
         ManagementAgent* agent = getBroker().getManagementAgent();
         if (agent != 0) {
-            std::string name(getId().getName());
+            std::string name(getId().str());
             std::string fullName(name);
             if (name.length() >= std::numeric_limits<uint8_t>::max())
                 name.resize(std::numeric_limits<uint8_t>::max()-1);

posted for review if it can't break anything (e.g. in QMF, backward compatibility or so) - in https://reviews.apache.org/r/25418/ .

Comment 2 Pavel Moravec 2014-09-12 07:56:16 UTC
Committed revision 1624473.

Comment 4 Frantisek Reznicek 2015-08-04 11:59:38 UTC
Patch in comment 1 has some side-effects also mentioned by patch reviewer.
I created separate defect bug 1249948 comment 5 with alternative patch.

Comment 5 Otavio Piske 2015-08-13 15:38:25 UTC
The fix was successfully verified.

Comment 9 errata-xmlrpc 2015-10-08 13:09:10 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHEA-2015-1879.html