Bug 3257 - Broken pipe after lots of connections.
Broken pipe after lots of connections.
Product: Samba 3.0
Classification: Unclassified
Component: libsmbclient
Other Linux
: P3 normal
: none
Assigned To: Derrell Lipman
Samba QA Contact
Depends on:
  Show dependency treegraph
Reported: 2005-11-12 07:39 UTC by Tim Hutt
Modified: 2005-12-05 20:43 UTC (History)
0 users

See Also:

Output of smb scanner. (126.75 KB, text/plain)
2005-11-15 15:53 UTC, Tim Hutt
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Hutt 2005-11-12 07:39:21 UTC
I have a program that basically does this:      
while (true)      
 for (IP = "172.31.[57-60,65].[1-245]")     
  cout << "Scanning <ip>";    
  if (smbc_open("smb://<ip>/") succeeds)     
   cout << "Share: <share>";    
  // Read a list of shares, and scan the shares for all the files.     
  // All the files are correctly closed.     
 cout << "Reinitialising libsmbclient";    
 context = smbc_set_context(NULL);    
 smbc_free_context(context, TRUE);    
 if (smbc_init(my_auth_data_fn, debug_level) != 0)    
   cout << "error";  
   return 1;   
But obviously more correctly. 
With the extra reinitialisation the scan works the first time, then has lots of broken pipes before 
scanning the second time (ie between the first and second scans). On the second scan it can't 
connect to *any* hosts. The second time it reinitialises the program segfaults (possibly because 
context is NULL). 
I'll attach a sample output.
Comment 1 Tim Hutt 2005-11-15 15:53:17 UTC
Created attachment 1573 [details]
Output of smb scanner.

This is the output from my scanning program.
Comment 2 Tim Hutt 2005-12-05 04:43:55 UTC
Solved it using this to reinitialise libsmbclient. It still says all the errors but then it works the next time anyway.

			SMBCCTX* context = smbc_set_context(NULL);	// Retrieve current context
			if (!context)
				cout << "Error! Context was null." << endl;
			smbc_free_context(context, true);			// Close all cached connections
			SMBCCTX *statcont1 = smbc_new_context();
			if (!statcont1)
				cout << "Error creating new context." << endl;
				return 1;
			statcont1->debug = 1;
			statcont1->callbacks.auth_fn = guest_auth_smbc_get_data;
			if (!smbc_init_context(statcont1))
				cout << "Error initialising new context." << endl;
				smbc_free_context(statcont1, false);
				return 1;

Comment 3 Derrell Lipman 2005-12-05 20:43:47 UTC
Problem appears to have been a file descriptor leak.  Thanks for the report.
Please test from SVN and reopen bug if problem persists.