Skip to content

inspectContainerCmd blocks until eventsCmd finished #602

Description

@igor-kostromin

I use 3.0.0 with default settings:

Lock lock = new ReentrantLock();
Condition cond = lock.newCondition();

String containerId = createContainerResponse.getId();

docker.eventsCmd()
                .withContainerFilter(createContainerResponse.getId())
                .exec(new EventsResultCallback() {
                    @Override
                    public void onNext(Event item) {
                        logger.info(String.format("Event from container [%s]: '%s'.", containerId, item));
                        if ("die".equals(item.getStatus())) {
                            try {
                                lock.lock();
                                cond.signal();
                            } finally {
                                lock.unlock();
                            }
                        }
                        super.onNext(item);
                    }
                });

docker.startContainerCmd(containerId).exec();

try {
            lock.lock();
            final int TIMEOUT_SECONDS = 5;
            if (!cond.await(TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
                // !!! This method doesnt return immediately, it waits the container to be died, and subsequently
                // there is not possible to kill container
                InspectContainerResponse inspectContainerResponse = docker.inspectContainerCmd(containerId).exec();
                String status = inspectContainerResponse.getState().getStatus();
                //
                if ("exited".equals(status) || "dead".equals(status)) {
                    if (inspectContainerResponse.getState().getOOMKilled()) {
                        logger.error(String.format("Container [%s] in '%s' state after OutOfMemory. Nothing to do.", containerId, status));
                    } else {
                        logger.warn(String.format("Container [%s] in '%s' state, nothing to do.", containerId, status));
                    }
                } else {
                    logger.error(String.format("Container [%s] in '%s' state after %d seconds, killing it..", containerId, status, TIMEOUT_SECONDS));
                    docker.killContainerCmd(containerId).exec();
                    logger.error(String.format("Container [%s] killed.", containerId));
                }
            }
        } catch (InterruptedException e) {
            logger.error("Thread interrupted", e);
            Thread.currentThread().interrupt();
        } finally {
            lock.unlock();
        }

This is reproduced not always. I will update this issue if will found more precise way to reproduce.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions