private void previousSessionTimeout(long eventTimestamp, WindowState state) {

        Map<String, Long> previousEndTimestamps = findAllPreviousEndTimestamps(state);
        SessionComplexEventChunk<StreamEvent> previousSession;

        //sort on endTimestamps
        if (previousEndTimestamps.size() > 1) {
            List<Map.Entry<String, Long>> toSort = new ArrayList<>();
            for (Map.Entry<String, Long> e : previousEndTimestamps.entrySet()) {
                toSort.add(e);
            }
            toSort.sort(Map.Entry.comparingByValue());
            LinkedHashMap<String, Long> map = new LinkedHashMap<>();
            for (Map.Entry<String, Long> e : toSort) {
                map.putIfAbsent(e.getKey(), e.getValue());
            }
            previousEndTimestamps = map;
        }

        for (Map.Entry<String, Long> entry : previousEndTimestamps.entrySet()) {
            previousSession = state.sessionMap.get(entry.getKey()).getPreviousSession();

            if (previousSession != null && previousSession.getFirst() != null &&
                    eventTimestamp >= previousSession.getAliveTimestamp()) {

                state.expiredEventChunk.setKey(previousSession.getKey());
                state.expiredEventChunk.setTimestamps(previousSession.getStartTimestamp(),
                        previousSession.getEndTimestamp(), previousSession.getAliveTimestamp());

                state.expiredEventChunk.add(previousSession.getFirst());
                previousSession.clear();
            } else {
                break;
            }

        }

    }
Checks all the previous sessions and get the expired sessions.
modules/siddhi-core/src/main/java/io/siddhi/core/query/processor/stream/window/SessionWindowProcessor.java