joannayang
asked on
how to fix broken pipe error in Java Application running on RedHat
I have a Java proxy server, which is public to the client, the client connects to the destination server through proxy server with SSL. The proxy server and destination server both got "Broken Pipe" Error, when the servers sent out xml messages. this happens intermittently. BTW, everything was fine when applications was running on windows until they were moved on to Linux. Can some experts help me out?
Following is the part code of proxy server pipe for fowarding messages to the destination server and sending messages back to the client.
protected class Pipe extends Thread
{
private BufferedInputStream inStream;
private BufferedOutputStream outStream;
private String label;
public Pipe(Socket in, Socket out, String label) throws IOException
{
super("Pipe");
inStream = new BufferedInputStream(in.get InputStrea m(), BUFFER_SIZE);
outStream = new BufferedOutputStream(out.g etOutputSt ream(), BUFFER_SIZE);
this.label = label + " " + in.getInetAddress().getHos tAddress()
+ " -> " + out.getInetAddress().getHo stAddress( );
}
public void run()
{
byte[] bytes = new byte[BUFFER_SIZE];
try
{
while (isRunning())
{
int count = inStream.read(bytes);
if (count > 0)
{
long readTime = System.currentTimeMillis() ;
outStream.write(bytes,0,co unt);
outStream.flush();
Thread.yield();
//transfer statistics
getServerTypeStatistics().
stat(ProxyByTypeStatistics .TRANSFER, count);
}
else if (count < 0)
throw new EOFException("Normal End of Stream");
else if (count == 0)
try
{
Thread.sleep(SLEEP_TIME);
}
catch (InterruptedException ie)
{
}
}
}
catch (EOFException eofe)
{
if ( running )
{
Log.getLog().log("INFO",la bel+" EOF: Socket closed");
shutdown();
}
}
catch (IOException ioe)
{
if ( running )
{
Log.getLog().log("ERROR"," PIPE ERROR"+label);
Log.getLog().log("ERROR",i oe);
shutdown();
}
}
catch (Throwable e)
{
Log.getLog().log("ERROR",e );
}
finally
{
try
{
inStream.close();
outStream.close();
}
catch (IOException ioe)
{
}
}
}
}
}
Following is the part code of proxy server pipe for fowarding messages to the destination server and sending messages back to the client.
protected class Pipe extends Thread
{
private BufferedInputStream inStream;
private BufferedOutputStream outStream;
private String label;
public Pipe(Socket in, Socket out, String label) throws IOException
{
super("Pipe");
inStream = new BufferedInputStream(in.get
outStream = new BufferedOutputStream(out.g
this.label = label + " " + in.getInetAddress().getHos
+ " -> " + out.getInetAddress().getHo
}
public void run()
{
byte[] bytes = new byte[BUFFER_SIZE];
try
{
while (isRunning())
{
int count = inStream.read(bytes);
if (count > 0)
{
long readTime = System.currentTimeMillis()
outStream.write(bytes,0,co
outStream.flush();
Thread.yield();
//transfer statistics
getServerTypeStatistics().
stat(ProxyByTypeStatistics
}
else if (count < 0)
throw new EOFException("Normal End of Stream");
else if (count == 0)
try
{
Thread.sleep(SLEEP_TIME);
}
catch (InterruptedException ie)
{
}
}
}
catch (EOFException eofe)
{
if ( running )
{
Log.getLog().log("INFO",la
shutdown();
}
}
catch (IOException ioe)
{
if ( running )
{
Log.getLog().log("ERROR","
Log.getLog().log("ERROR",i
shutdown();
}
}
catch (Throwable e)
{
Log.getLog().log("ERROR",e
}
finally
{
try
{
inStream.close();
outStream.close();
}
catch (IOException ioe)
{
}
}
}
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it is socket connection, basically, the proxy establishs the connection for the client and the destination server.
OK
Someone said it maybe caused by the network, or the data has bad charactor, or the outStream is filling up faster than it is read off.
It may happen some time, you can try by making sender and receiver in seperate thread.
ASKER
do you know whether it is linux resources issues? I have my application running on windows 2000 for a year, never had this type of error, but once I moved to linux, it happened. Someone said it maybe resources issues( memory, cpu, multi-threads limits or message buffer limits). What do you think? Thanks Very Much!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
memory corruption? how could that happen? Do you mean I probably had "OutOfMemory" error or Physical memory has problem? If it was memory corruption, how do I prevent it or fix it? Your metion about memory corruption did reminds me I had two identical servers running at the same time, the one had broken pipe errors with very high memory usage, could it be the problem?
Thanks
Thanks
In the case of memory problem then linux would have given Segmentation fault.
Also this code was working fine in windows and hence there will not be memory problem
Also this code was working fine in windows and hence there will not be memory problem
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
still could not figure it out and fix it. If any of you have a great idea, please give me some suggestions!
Thanks!
Thanks!
what are the debugging steps you took so far ?
ASKER
what could cause the broken pipe? why the socket was killed? my application will never kill it when the servers are running.
Someone said it maybe caused by the network, or the data has bad charactor, or the outStream is filling up faster than it is read off.
any idea about these?
Thanks