Hi,
(tested with 2.0.14 and 2.4.5)
When I open up more than 1024 sockets, couchbase says it times out. (but it is out of FD space as far as I see from the code and old bugs)
I have ulimit -n 1000000, and the operations on the opened sockets work without issue (in my bigger app).
The code that demonstrates the failure is attached, just set the number of 1023 to 1024 and it fails. (I cannot upload any file other than images, so I pasted, very probably horribly mangled.)
#include <stdio.h>
#include <unistd.h>
#include <libcouchbase/couchbase.h>
#include <memory.h>
static void bootstrap_callback(lcb_t instance, lcb_error_t err){
if (err == LCB_SUCCESS) {
printf(
"INFO; %s: Instance is ready.\n",
__func__);
} else {
printf("ERROR; %s: Error %s", __func__,
lcb_strerror(instance, err));
}
}
int cbi_init(lcb_t *instance) {
struct lcb_create_st create_options;
lcb_error_t err;
memset(&create_options, 0, sizeof(create_options));
create_options.v.v0.host = "localhost.localdomain:8091";
create_options.v.v0.user = "";
create_options.v.v0.passwd = "";
create_options.v.v0.bucket = "default";
err = lcb_create(instance, &create_options);
if (err != LCB_SUCCESS) {
printf("ERROR; %s: Failed to create libcouchbase instance: %s\n",
__func__, lcb_strerror(NULL, err));
return 0;
}
/* Set up the handlers */
(void) lcb_set_bootstrap_callback(*instance, bootstrap_callback);
/*
* Initiate the connect sequence in libcouchbase
*/
if ((err = lcb_connect(*instance)) != LCB_SUCCESS) {
printf(
"ERROR; %s: Failed to initiate connect: %s\n",
__func__, lcb_strerror(NULL, err));
return 0;
} else {
printf(
"INFO; %s: Connect request started \n",
__func__);
}
/* Run the event loop and wait until we've connected */
// finish this off completely.
// I do not run the normal yield function here as it will call the event loop anyway and I want to completely finish this.
lcb_wait(*instance);
return 1;
}
#define NR_FDS 1015
const char *testfilename = "/tmp/bla.txt";
FILE* fd[NR_FDS];
int main(void)
{
lcb_t instance;
unlink(testfilename);
FILE *f = fopen(testfilename,"w");
if (!f){
printf("ERROR; cannot create test file\n");
return(1);
}
fwrite("test",1,4,f);
fclose(f);
printf("Opening FD\n");
int i;
for (i = 0; i < NR_FDS; i++) {
fd[i] = fopen("/tmp/bla.txt","r");
if (!fd[i]) {
printf("ERROR; cannot open more than %d FDs\n",i);
return(1);
}
}
printf("Inspecting reading from FDs\n");
char str[100];
for (i = 0; i < NR_FDS; i++) {
if (fread(str,1,4,fd[i]) != 4) {
printf("ERROR; cannot read from more than %d FDs\n",i);
return(1);
}
}
printf("Opening couchbase connection\n");
cbi_init(&instance);
printf("closing\n");
lcb_destroy(instance);
return 0;
}