Github user kevinxu021 commented on a diff in the pull request:

    
https://github.com/apache/incubator-trafodion/pull/1209#discussion_r136739857
  
    --- Diff: 
dcs/src/main/java/org/trafodion/dcs/master/listener/ListenerWorker.java ---
    @@ -86,39 +86,43 @@ public void run() {
             DataEvent dataEvent;
         
             while(true) {
    -            // Wait for data to become available
    -            synchronized(queue) {
    -                while(queue.isEmpty()) {
    -                    try {
    -                        queue.wait();
    -                    } catch (InterruptedException e) {
    +            try {
    +                // Wait for data to become available
    +                synchronized(queue) {
    +                    while(queue.isEmpty()) {
    +                        try {
    +                            queue.wait();
    +                        } catch (InterruptedException e) {
    +                        }
                         }
    +                    dataEvent = queue.remove(0);
                     }
    -                dataEvent = queue.remove(0);
    -            }
    -            SelectionKey key = dataEvent.key;
    -            SocketChannel client = (SocketChannel) key.channel();
    -            Socket s = client.socket();
    -            ClientData clientData = (ClientData) key.attachment();
    -            ListenerService server = dataEvent.server;
    -            dataEvent.key = null;
    -            dataEvent.server = null;
    -            
    -            switch (clientData.hdr.getOperationId()){
    -                case ListenerConstants.DCS_MASTER_GETSRVRAVAILABLE:
    -                    clientData = 
requestGetObjectRef.processRequest(clientData, s);
    -                    break;
    -                case ListenerConstants.DCS_MASTER_CANCELQUERY:
    -                    clientData = 
requestCancelQuery.processRequest(clientData, s);
    -                    break;
    -                default:
    -                    clientData = requestUnknown.processRequest(clientData, 
s);
    -                    break;
    +                SelectionKey key = dataEvent.key;
    +                SocketChannel client = (SocketChannel) key.channel();
    +                Socket s = client.socket();
    +                ClientData clientData = (ClientData) key.attachment();
    +                ListenerService server = dataEvent.server;
    +                dataEvent.key = null;
    +                dataEvent.server = null;
    +
    +                switch (clientData.hdr.getOperationId()){
    +                    case ListenerConstants.DCS_MASTER_GETSRVRAVAILABLE:
    +                        clientData = 
requestGetObjectRef.processRequest(clientData, s);
    +                        break;
    +                    case ListenerConstants.DCS_MASTER_CANCELQUERY:
    +                        clientData = 
requestCancelQuery.processRequest(clientData, s);
    +                        break;
    +                    default:
    +                        clientData = 
requestUnknown.processRequest(clientData, s);
    +                        break;
    +                }
    +                // Return to sender
    +                int requestReply = clientData.requestReply;
    +                key.attach(clientData);
    +                server.send(new PendingRequest(key, requestReply));
    +            } catch (Exception e){
    +                LOG.error("Unexpected Exception", e);
    --- End diff --
    
    I would suggest to print 100 times instead of exiting. Because 100 
NullPointExceptions belongs to 100 requests, that will not hang the rest of the 
requests. it'll not impact each other. By the way, as you see, there are some 
changes in a internal request catching Exception and return back to the client, 
then the outer catch is for the exception out of the request. It doesn't have 
so much code which rarely has chance for the exception out of control. if you 
still worry about it, we can add a limitation for the number of the exceptions 
in a reasonable time range.
    
    OutOfMemoryError will lead to process exiting and client will get socket 
timeout exception in 60s, at this time, DCSMaster will not hang.
    
    Again, in the past, the request from client lead to the issue, as you see, 
in the loop, there should be a different request for each round of loop. Unless 
the client send the same request again and again, it should be a big problem.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to