Skip to content

Commit

Permalink
TEIIDDES-1971: Workaround for avoiding annoying errors in server log
Browse files Browse the repository at this point in the history
* "Connection reset by peer" messages appear in the jboss log due to making
  a socket connection from the host heatbeat requests but never using the
  socket. Almost like the server is upset that we connected then closed!!

* The read socket stream normally returns the hostname of the server so
  this is logged along with a nice message, ensuring the socket is used
  before closing it.

* The successfully connected message is useful for debug purposes but is
  unnecessary for users so implements tracing for the plugin in order to
  only log the messages in debug mode.
  • Loading branch information
Paul Richardson committed Dec 20, 2013
1 parent 6f2f295 commit 7eadfad
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
17 changes: 17 additions & 0 deletions plugins/org.teiid.designer.dqp/.options
@@ -0,0 +1,17 @@
# Master debug switch for plugin
org.teiid.designer.dqp/debug = false

# Option indicating if a trace message should be logged when a preview job is asked if it should run.
org.teiid.designer.dqp/debug/preview/jobs/jobShouldRun = false

# Option indicating if a trace message should be logged when a preview job is started.
org.teiid.designer.dqp/debug/preview/jobs/jobStart = false

# Option indicating if a trace message should be logged when a preview job is finished running.
org.teiid.designer.dqp/debug/preview/jobs/jobDone = false

# Option indicating if a trace message should be logged for how long a preview job took to run.
org.teiid.designer.dqp/debug/preview/jobs/jobDuration = false

# Option indicating if a trace message should be logged for the jboss host connection check
org.teiid.designer.dqp/debug/jboss/connection = false
Expand Up @@ -52,4 +52,8 @@ public interface DebugConstants {
*/
String PREVIEW_JOB_DURATION = PREVIEW_JOBS + "/jobDuration"; //$NON-NLS-1$

/**
* Option indicating if a trace message should be logged for the jboss host connection check
*/
String JBOSS_CONNECTION = DEBUG + "/jboss/connection"; //$NON-NLS-1$
}
Expand Up @@ -7,11 +7,16 @@
*/
package org.teiid.designer.runtime.adapter;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.InetSocketAddress;
import java.net.Socket;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
import org.teiid.designer.runtime.DebugConstants;
import org.teiid.designer.runtime.DqpPlugin;

/**
Expand Down Expand Up @@ -43,6 +48,7 @@ public static boolean isJBossServerConnected(IServer parentServer, JBossServer j
*/
protected static boolean isHostConnected(String host, int port) throws Exception {
Socket socket = null;
Reader in = null;
InetSocketAddress endPoint = new InetSocketAddress(host, port);

if (endPoint.isUnresolved()) {
Expand All @@ -54,11 +60,68 @@ protected static boolean isHostConnected(String host, int port) throws Exception
socket = new Socket();
socket.connect(endPoint, 1024);

/*
* This may not seem necessary since a socket connection
* should be enough. However, TEIIDDES-1971 has shown
* that without actually using the socket, 'Connection reset
* by peer' messages with be reported in the server log.
*/
InputStream socketReader = socket.getInputStream();

final char[] buffer = new char[100];
in = new InputStreamReader(socketReader);
int rsz = in.read(buffer, 0, buffer.length);
if (rsz == -1) {
if (DqpPlugin.getInstance().isDebugOptionEnabled(DebugConstants.JBOSS_CONNECTION)) {
/*
* Only need to log this with debug tracing turned on.
*/
String message = DqpPlugin.Util.getString("jbossServerConnectionStreamEmpty", host, port); //$NON-NLS-1$
IStatus status = new Status(IStatus.OK, DqpPlugin.PLUGIN_ID, message);
DqpPlugin.Util.log(status);
}
return false;
}

StringBuffer output = new StringBuffer();
for (int i = 0; i < buffer.length; ++i) {
if (Character.isLetterOrDigit(buffer[i])) {
output.append(buffer[i]);
}
}

if (DqpPlugin.getInstance().isDebugOptionEnabled(DebugConstants.JBOSS_CONNECTION)) {
/*
* Only need to log this with debug tracing turned on.
*/
String message = DqpPlugin.Util.getString("jbossServerHeartBeat", host, port, output); //$NON-NLS-1$
IStatus status = new Status(IStatus.OK, DqpPlugin.PLUGIN_ID, message);
DqpPlugin.Util.log(status);
}

return true;
} catch (Exception ex) {
if (DqpPlugin.getInstance().isDebugOptionEnabled(DebugConstants.JBOSS_CONNECTION)) {
/*
* Only need to log this with debug tracing turned on.
*/
DqpPlugin.Util.log(ex);
}
return false;
} finally {
if (socket != null && socket.isConnected()) {
socket.close();
socket = null;
try {
if (in != null)
in.close();

if (socket != null && socket.isConnected()) {
socket.close();
socket = null;
}
} catch (Exception ex2) {
/*
* Unlikely event that socket did not close correctly.
*/
DqpPlugin.Util.log(ex2);
}
}
}
Expand Down
Expand Up @@ -136,6 +136,8 @@ jdbcInfoType = JDBC
# TeiidServerAdapterUtil
jbossServerNotStartedMessage = No Teiid Instance found (server not started)
jbossServerConnectionFailureMessage = Failed to connect to the jboss server at {0}
jbossServerConnectionStreamEmpty = The Jboss Server on {0}\:{1} returned an empty stream
jbossServerHeartBeat = A Jboss Server on {0}\:{1} correctly answered a host-available request with "{2}"

# OrphanedTeiidServerException
OrphanedTeiidServerException.message = The Teiid Instance {0} does not have a parent jboss server
Expand Down

0 comments on commit 7eadfad

Please sign in to comment.