Skip to content

RandomAccessDataFile should use Semaphore.acquireUninterruptibly #6682

@hengyunabc

Description

@hengyunabc

In org.springframework.boot.loader.data.RandomAccessDataFile , when read file, it will call Semaphore.acquire. When the current thread state is interrupted, it will throw InterruptedException. The thread will failed to read file.

// java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(int arg
    public final void acquireSharedInterruptibly(int arg)
            throws InterruptedException {
        if (Thread.interrupted())
            throw new InterruptedException();
        if (tryAcquireShared(arg) < 0)
            doAcquireSharedInterruptibly(arg);
    }

Consider the following case:

  1. A executor submit a Runnable task, then call FutureTask.cancel to cancel it.
  2. The Runnable task thread state is marked as interrupted, but it will continue running.
  3. The Runnable task thread try to load class A, the spring boot classloader will use RandomAccessDataFile to read A.class file from fat jar. But RandomAccessDataFile will throw IOException, because the current thread state is interrupted.
  4. The clsssloader thow NoClassDefFoundError

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions