Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-3840

Race condition in the RollbackLocalFilterTests

    XMLWordPrintable

    Details

      Description

      The error looks like:

      org.springframework.integration.sftp.inbound.RollbackLocalFilterTests > testRollback FAILED
          java.lang.NullPointerException at RollbackLocalFilterTests.java:56
      

      And that is just because of this code:

      @Test
      public void testRollback() throws Exception {
      	assertTrue(this.crash.getLatch().await(10, TimeUnit.SECONDS));
      	assertEquals("sftpSource1.txt", this.crash.getFile().getName());
      }
      

      Which relies on the this non-robust code below:

      public void handle(File in) {
      	latch.countDown();
      	if (this.shouldCrash.compareAndSet(false, true)) {
      		throw new RuntimeException("foo");
      	}
      	this.file = in;
      }
      

      where we really can see that latch is released before setting the value for the file property.

      For me the fix looks like:

      public void handle(File in) {
      	if (this.shouldCrash.compareAndSet(false, true)) {
      		latch.countDown();
      		throw new RuntimeException("foo");
      	}
      	this.file = in;
      	latch.countDown();
      }
      

      When we countDown the first time together with the throwing Exception and the second time only after the property population. Both cases are separate and don't affect each other. But yes, they operate on the same latch !

        Attachments

          Activity

            People

            Assignee:
            abilan Artem Bilan
            Reporter:
            abilan Artem Bilan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: