title: Why do SqS messages sometimes remain in-flight on queue
body: <p>I'm using Amazon SQS queues in a very simple way. Usually, messages are written and immediately visible and read. Occasionally, a message is written, and remains In-Flight(Not Visible) on the queue for several minutes. I can see it from the console. Receive-message-wait time is 0, and Default Visibility is 5 seconds. It will remain that way for several minutes, or until a new message gets written that somehow releases it. A few seconds delay is ok, but more than 60 seconds is not ok.</p>
  
  <p>There a 8 reader threads that are long polling always, so its not that something is not trying to read it, they are.</p>
  
  <p><strong>Edit</strong> : To be clear, none of the consumer reads are returning any messages at all and it happens regardless of whether or not the console is open. In this scenario, only one message is involved, and it is just sitting in the queue invisible to the consumers.</p>
  
  <p>Has anyone else seen this behavior and what I can do to improve it?</p>
  
  <p>Here is the sdk for java I am using:</p>
  
  <pre><code>&lt;dependency&gt;
    &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
    &lt;artifactId&gt;aws-java-sdk&lt;/artifactId&gt;
    &lt;version&gt;1.5.2&lt;/version&gt;
  &lt;/dependency&gt;     
  </code></pre>
  
  <p>Here is the code that does the reading (max=10,maxwait=0 startup config):</p>
  
  <pre><code>void read(MessageConsumer consumer) {
  
    List&lt;Message&gt; messages = read(max, maxWait);
  
    for (Message message : messages) {
      if (tryConsume(consumer, message)) {
        delete(message.getReceiptHandle());
      }
    }
  }
  
  private List&lt;Message&gt; read(int max, int maxWait) {
  
    AmazonSQS sqs = getClient();
    ReceiveMessageRequest rq = new ReceiveMessageRequest(queueUrl);
    rq.setMaxNumberOfMessages(max);
    rq.setWaitTimeSeconds(maxWait);
    List&lt;Message&gt; messages = sqs.receiveMessage(rq).getMessages();
  
    if (messages.size() &gt; 0) {
      LOG.info("read {} messages from SQS queue",messages.size());
    }
  
    return messages;
  }
  </code></pre>
  
  <p>The log line for "read .." never appears when this is happening, and its what causes me to go in with the console and see if the message is there or not, and it is. </p>