You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Zhenliang Su (JIRA)" <ji...@apache.org> on 2019/06/14 08:46:00 UTC
[jira] [Comment Edited] (SSHD-921) OutOfMemory Error in extreme
situations
[ https://issues.apache.org/jira/browse/SSHD-921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16863840#comment-16863840 ]
Zhenliang Su edited comment on SSHD-921 at 6/14/19 8:45 AM:
------------------------------------------------------------
I think a simple modification is to change the org.apache.sshd.agent.local.AgentForwardedChannel#request function:
{code:java}
protected Buffer request(Buffer buffer) throws IOException {
synchronized (messages) {
try {
OutputStream outputStream = getInvertedIn();
outputStream.write(buffer.array(), buffer.rpos(), buffer.available());
outputStream.flush();
Window wLocal = getLocalWindow();
wLocal.consumeAndCheck(buffer.available());
if (messages.isEmpty()) {
long start = System.currentTimeMillis();
long authTimeout = getLongProperty(FactoryManager.AUTH_TIMEOUT, FactoryManager.DEFAULT_AUTH_TIMEOUT);
messages.wait(authTimeout + 2000); // The 2000 here is just for a little longer.
long end = System.currentTimeMillis();
if (end - start > authTimeout) {
throw new IOException("wait timeout");
}
}
return messages.poll();
} catch (InterruptedException e) {
throw (IOException) new InterruptedIOException("Interrupted while polling for messages").initCause(e);
}
}
}
{code}
was (Author: smoking):
I think a simple modification is to change the org.apache.sshd.agent.local.AgentForwardedChannel#request function:
{code:java}
protected Buffer request(Buffer buffer) throws IOException {
synchronized (messages) {
try {
OutputStream outputStream = getInvertedIn();
outputStream.write(buffer.array(), buffer.rpos(), buffer.available());
outputStream.flush();
Window wLocal = getLocalWindow();
wLocal.consumeAndCheck(buffer.available());
if (messages.isEmpty()) {
long start = System.currentTimeMillis();
long authTimeout = getLongProperty(FactoryManager.AUTH_TIMEOUT, FactoryManager.DEFAULT_AUTH_TIMEOUT);
messages.wait(authTimeout + 2000); // The 2000 here is just for a little longer.
long end = System.currentTimeMillis();
if (end - start > authTimeout) {
throw new IOException("wait timeout");
}
}
return messages.poll();
} catch (InterruptedException e) {
throw (IOException) new InterruptedIOException("Interrupted while polling for messages").initCause(e);
}
}
}
{code}
> OutOfMemory Error in extreme situations
> ---------------------------------------
>
> Key: SSHD-921
> URL: https://issues.apache.org/jira/browse/SSHD-921
> Project: MINA SSHD
> Issue Type: Bug
> Affects Versions: 1.7.0, 2.0.0
> Reporter: Zhenliang Su
> Assignee: Goldstein Lyor
> Priority: Major
> Attachments: Main.java, jstack.txt
>
>
> The demo code run in my local machine.
> When I 'ssh root@127.0.0.1 -p 2233', my demo will use the agent forwarding feature to login 10.10.16.201.
> In most cases, it's ok. But in few cases, for example, client disconnect suddenly, it will lead to OutOfMemory Error.
> To simulate this scenario of OutOfMemory Error, I did some trick to the sshd code:
> 1. In org.apache.sshd.common.future.DefaultSshFuture#setValue:
> {code:java}
> public void setValue(Object newValue) {
> // to simulate race condition
> try {
> Thread.sleep(10);
> } catch (Exception e) {
> // ignore
> }
> synchronized (lock) {
> // Allow only once.
> if (result != null) {
> return;
> }
> result = (newValue != null) ? newValue : GenericUtils.NULL;
> lock.notifyAll();
> }
> notifyListeners();
> }
> {code}
> 2. In org.apache.sshd.agent.local.AgentForwardedChannel#doWriteData:
> {code:java}
> protected void doWriteData(byte[] data, int off, long len) throws IOException {
> ValidateUtils.checkTrue(len <= Integer.MAX_VALUE, "Data length exceeds int boundaries: %d", len);
> Buffer message = null;
> synchronized (receiveBuffer) {
> receiveBuffer.putBuffer(new ByteArrayBuffer(data, off, (int) len));
> // to simulate client disconnect suddenly
> if (false && receiveBuffer.available() >= 4) {
> off = receiveBuffer.rpos();
> len = receiveBuffer.getInt();
> receiveBuffer.rpos(off);
> if (receiveBuffer.available() >= (4 + len)) {
> message = new ByteArrayBuffer(receiveBuffer.getBytes());
> receiveBuffer.compact();
> }
> }
> }
> if (message != null) {
> synchronized (messages) {
> messages.offer(message);
> messages.notifyAll();
> }
> }
> }
> {code}
> After two munites, my console displayed '[sshd-SshClient[720b3c53]-timer-thread-1] INFO org.apache.sshd.client.session.ClientSessionImpl - Disconnecting(ClientSessionImpl[root@/10.10.16.201:8022]): SSH2_DISCONNECT_PROTOCOL_ERROR - Session has timed out waiting for authentication after 120000 ms.' every second, and finally lead to OutOfMemory Error.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org