Exception java.net.SocketException: Connection reset

I have written a code to parse a csv file from a proxy server.But after a specific time interval (after parsing some csv lines), it is giving this error:

DEBUG [csvFile-267] Successfully parsed usage CSV file for 30 rows
ERROR  [csvFile-271] Exception occurred in csvFile() 
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)  

When I am pinging on that server I am getting "request timeout" in some cases. Is that a server configuration problem, or network, or coding?

My Code:

    while ((line = reader.readLine()) != null) {
            UsageResponse usageResponse = new UsageResponse();
            ErrorDetails errorDetails = new ErrorDetails();
            try {
                //fileData = line.split(splitby);
                fileData = line.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");

                if (isheaderReadable) {

                    for (int headerCounter = 0; headerCounter < fileData.length; headerCounter++) {
                        if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_REPORT_START_DATE)) {
                            usageStartDateLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_REPORT_END_DATE)) {
                            usageEndDateLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_ACCOUNT_ID)) {
                            linkedAccountLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_CODE)) {
                            productCodeLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_USAGE_TYPE)) {
                            usageTypeLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_USAGE_AMOUNT)) {
                            usageAmountLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_UNBLENDED_RATE)) {
                            unBlendedrateLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_UNBLENDED_COST)) {
                            unBlendedCostLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_BLENDED_RATE)) {
                            blendedrateLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_BLENDED_COST)) {
                            blendedCostLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_ITEM_DESCRIPTION)) {
                            lineItemDescriptionLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_LOCATION)) {
                            productLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_SKU)) {
                            productSKULocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_NAME)) {
                            productNameLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_GROUP)) {
                            productGroupLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_LINE_ITEM_TYPE)) {
                            lineTypeLocation = headerCounter;
                        }
                    }
                    isheaderReadable = false;
                } else {

                    if (!fileData[lineTypeLocation].equalsIgnoreCase("Tax") && !fileData[lineTypeLocation].equalsIgnoreCase("DiscountedUsage")) {
                        usageResponse.setProductCode(fileData[productCodeLocation]);
                        usageResponse.setUsageStartDate(fileData[usageStartDateLocation]);
                        usageResponse.setUsageEndDate(fileData[usageEndDateLocation]);

                        if (fileData[blendedCostLocation] != null && !fileData[blendedCostLocation].isEmpty()) {
                            usageResponse.setBlendedCost(Double.parseDouble(fileData[blendedCostLocation]));
                        }
                        if (fileData[unBlendedCostLocation] != null && !fileData[unBlendedCostLocation].isEmpty()) {
                            usageResponse.setUnblendedCost((Double.parseDouble(fileData[unBlendedCostLocation])));
                        }
                        if (fileData[blendedrateLocation] != null && !fileData[blendedrateLocation].isEmpty()) {
                            usageResponse.setBlendedRate(Double.parseDouble(fileData[blendedrateLocation]));
                        }
                        if (fileData[unBlendedrateLocation] != null && !fileData[unBlendedrateLocation].isEmpty()) {
                            usageResponse.setUnblendedRate((Double.parseDouble(fileData[unBlendedrateLocation])));
                        }

                        usageResponse.setItemDescription(fileData[lineItemDescriptionLocation]);

                        if (fileData[usageAmountLocation] != null && !fileData[usageAmountLocation].isEmpty()) {
                            usageResponse.setUsageAmount(Double.parseDouble(fileData[usageAmountLocation]));
                        }
                        usageResponse.setUsageType(fileData[usageTypeLocation]);
                        usageResponse.setLocation(fileData[productLocation]);
                        usageResponse.setLinkedAccountId(fileData[linkedAccountLocation]);
                        usageResponse.setProductSKU(fileData[productSKULocation]);
                        usageResponse.setProductName(fileData[productNameLocation]);
                        usageResponse.setProductGroup(fileData[productGroupLocation]);
                        usageResponseList.add(usageResponse);
                    }
                }
            } catch (AWSCostAndUsageReportException e) {
                logger.error("Error is occurred during retrieving usage amounts ", e);
                errorDetails.setCode(e.getErrorCode());
                errorDetails.setMessage(e.getMessage());
                usageResponse.setErrorDetails(errorDetails);
            }
            listUsage.setUsageResponses(usageResponseList);

        }

Upvotes: 0

Views: 6917

Answers (1)

Dax Loy
Dax Loy

Reputation: 172

If you are pinging the server and getting a request time out that means that what ever you are pinging is not receiving your ping. Also, since the error message states that the Connection has reset that could be indicative of the server loosing connection to your application. In short, the connection to the server is made, but when you start to talk to the server it resets the connection.

Take that with a grain of salt because the code you have supplied does not seem to be the raw code that is handling the socket itself, so I cannot speak on the behalf of the code.

Tldr; Server is timing out so the connection is resetting. Could also be the code actually handling the socket

Upvotes: 1

Related Questions