Uploaded image for project: 'Hama'
  1. Hama
  2. HAMA-972

Synchronization on local variable

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Not A Problem
    • None
    • None
    • bsp core
    • None

    Description

      I'm not sure that the synchronization of the following code is proper.
      In the code, it uses the call variable as a lock. But it's a local variable. So whenever this function is called, the lock is changed. I think this is a bug... What do you think..? Is there anything that I'm missing..?

      // Client.java 
      public Writable call(Writable param, ConnectionId remoteId)
            throws InterruptedException, IOException {
          Call call = new Call(param);
      
          Connection connection = getConnection(remoteId, call);
      
          connection.sendParam(call); // send the parameter
          boolean interrupted = false;
      
          synchronized (call) {
            int callFailCount = 0;
            while (!call.done) {
              try {
                call.wait(1000); // wait for the result
                // prevent client hang from response error
                if (callFailCount++ == IPC_CLIENT_CONNECT_MAX_RETRIES_DEFAULT)
                  break;
              } catch (InterruptedException ie) {
                interrupted = true;
              }
            }
      
            if (interrupted) {
              // set the interrupt flag now that we are done waiting
              Thread.currentThread().interrupt();
      
            }
      
            if (call.error != null) {
              if (call.error instanceof RemoteException) {
                call.error.fillInStackTrace();
                throw call.error;
              } else { // local exception
                // use the connection because it will reflect an ip change,
                // unlike
                // the remoteId
                throw wrapException(connection.getRemoteAddress(), call.error);
              }
            } else {
              return call.value;
            }
          }
        }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            seedengine JongYoon Lim
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: