public void notifyOfError(Throwable error) {
        if (error != null && this.error == null) {
            this.error = error;

            // this should wake up any blocking calls
            try {
                connectedSocket.close();
            } catch (Throwable ignored) {
            }
            try {
                socket.close();
            } catch (Throwable ignored) {
            }
        }
    }
@Test
    void testIteratorWithException() throws Exception {

        final SocketStreamIterator<Long> iterator =
                new SocketStreamIterator<>(LongSerializer.INSTANCE);

        // asynchronously set an error
        new Thread() {
            @Override
            public void run() {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ignored) {
                }
                iterator.notifyOfError(new Exception("test"));
            }
        }.start();

        assertThatThrownBy(iterator::hasNext)
                .isInstanceOf(RuntimeException.class)
                .hasMessageContaining("test");
    }