[JAVA-579] when i query data,i have got a expetion:SocketException handling request, closing client connection: 9001 socket exception [2] server in logfile Created: 31/May/12  Updated: 11/Sep/19  Resolved: 04/Jun/12

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: ben.s Assignee: Unassigned
Resolution: Done Votes: 0
Labels: driver, query
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

linux,64bit.


Attachments: Text File logsingle.log    

 Description   

==============================background==================================
I start mongodb use like this(single server): -dbpath=/usr/local/mongodb-2.0.5/data/db1 -poart=2715 -maxConns=1000 -logpath=/usr/local/mongodb-2.0.5/log/logsingle.log

the java code to operator mongodb to query data like this:

private static Mongo mongo=null;
static{
    MongoOptions options = new MongoOptions();
    options.autoConnectRetry = true;
    options.connectionsPerHost=1000;
    options.threadsAllowedToBlockForConnectionMultiplier=10;
    options.connectTimeout = 6000;
    options.maxAutoConnectRetryTime = 12000;
    options.maxWaitTime = 12000; 
    options.socketKeepAlive = true;
    options.socketTimeout = 2000;
    mongo = new Mongo(new ServerAddress("localhost", 2715),options);
}
 
public void queryData(Object key){
   DB db = mongo.getDB(DATABASE_NAME);
   DBCollection dbcollection = db.getCollection(collection);
   BasicDBObject doc = new BasicDBObject();
   doc.put("key", key);
   DBCursor cursor = dbcollection.find(doc);
}

================================ERROR=======================================
i am stress test the mongodb use http_client tool. use 10 thread to test the query. after some time,the server is died.and cpu is 100%.and then i am got the exception from logfile like this:
Thu May 31 14:18:10 [conn154] query mydb.ben\ query:

{ key: "1" }

nscanned:53832616 reslen:20 11032064ms
Thu May 31 14:18:10 [conn154] SocketException handling request, closing client connection: 9001 socket exception [2] server [127.0.0.1:53887]
Thu May 31 14:18:11 [conn173] query mydb.ben\ query:

{ key: "6" }

nscanned:53832616 reslen:20 11014949ms
Thu May 31 14:18:11 [conn173] SocketException handling request, closing client connection: 9001 socket exception [2] server [127.0.0.1:53906]
Thu May 31 14:18:12 [conn160] query mydb.ben\ query:

{ key: "7" }

nscanned:53832616 reslen:20 11028041ms
Thu May 31 14:18:12 [conn160] SocketException handling request, closing client connection: 9001 socket exception [2] server [127.0.0.1:53893]
Thu May 31 14:18:14 [conn161] query mydb.ben\ query:

{ key: "7" }

nscanned:53832616 reslen:20 11029619ms
Thu May 31 14:18:14 [conn161] SocketException handling request, closing client connection: 9001 socket exception [2] server [127.0.0.1:53894]
Thu May 31 14:18:17 [conn149] query mydb.ben\ query:

{ key: "6" }

nscanned:53832616 reslen:20 11045234ms
Thu May 31 14:18:18 [conn149] SocketException handling request, closing client connection: 9001 socket exception [2] server [127.0.0.1:53882]
Thu May 31 14:18:24 [conn151] query mydb.ben\ query:

{ key: "6" }

nscanned:53832616 reslen:20 11049350ms
Thu May 31 14:18:24 [conn151] SocketException handling request, closing client connection: 9001 socket exception [2] server [127.0.0.1:53884]
Thu May 31 14:18:25 [conn157] query mydb.ben\ query:

{ key: "6" }

nscanned:53832616 reslen:20 11044775ms
Thu May 31 14:18:25 [conn157] SocketException handling request, closing client connection: 9001 socket exception [2] server [127.0.0.1:53890]
Thu May 31 14:18:32 [conn171] query mydb.ben\ query:

{ key: "5" }

nscanned:53832616 reslen:20 11037628ms
Thu May 31 14:18:32 [conn171] SocketException handling request, closing client connection: 9001 socket exception [2] server [127.0.0.1:53904]
Thu May 31 14:18:37 [conn155] query mydb.ben\ query:

{ key: "6" }

nscanned:53832616 reslen:20 11059201ms
Thu May 31 14:18:37 [conn155] SocketException handling request, closing client connection: 9001 socket exception [2] server [127.0.0.1:53888]
Thu May 31 14:18:40 [conn148] query mydb.ben\ query:

{ key: "1" }

nscanned:53832616 reslen:20 11067425ms
Thu May 31 14:18:40 [conn148] SocketException handling request, closing client connection: 9001 socket exception [2] server [127.0.0.1:53881]

i wonder is options.socketKeepAlive = true; trigger the error.because when use this config,the error is start to appear.but i'm not sure.



 Comments   
Comment by ben.s [ 04/Jun/12 ]

i test DBCursor.close(),but it's not working.when i change the data in collection,one query return one data,only 8 bit,it's work very well.

Comment by Jeffrey Yemin [ 04/Jun/12 ]

Make sure you call DBCursor.close()

Comment by ben.s [ 04/Jun/12 ]

thanks jeff.

Comment by ben.s [ 04/Jun/12 ]

it's just test code,there's no more code.mybe i found why the connection can't close.i test one query,it return mass data,and spend a lot of time into it.when mongodb want to close a connection cause there is too many connection on the server but the connection is busy,so it's failed.

Comment by Jeffrey Yemin [ 04/Jun/12 ]

There must be more code, right? None of the code you included initiates a connection to the server (DBCollection.find(..) doesn't actually send the query. Nothing happens until you start iterating the cursor). Looking at the server logs, the queries seems to be happening, so I'm assuming there must be more code that's not being shown here.

For future reference, this kind of question is better handled on the mongodb-users list.

Generated at Thu Feb 08 08:52:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.