JCIFS jcifs.smb.SmbException: A device attached to the system is not functioning
java, jcifs
Solution
Possibly found the solution: It looks as if you can only open 16384 files via new SmbFile() per session. You have to call the SmbFileInputStream.close() which calls the package private SmbFile.close() which seems to send a SmbComClose message to the server which closes the request and releases the resource.
Problem
We are using JCIFS (1.3.17) to load image files from a Windows 2003 file server. Unfortunatly loading stops working after 16384 files and we get an the following exception when trying to access more files: ``` jcifs.smb.SmbException: A device attached to the system is not functioning. at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:563) ~[jcifs-1.3.17.jar:na] at jcifs.smb.SmbTransport.send(SmbTransport.java:663) ~[jcifs-1.3.17.jar:na] at jcifs.smb.SmbSession.send(SmbSession.java:238) ~[jcifs-1.3.17.jar:na] at jcifs.smb.SmbTree.send(SmbTree.java:119) ~[jcifs-1.3.17.jar:na] at jcifs.smb.SmbFile.send(SmbFile.java:775) ~[jcifs-1.3.17.jar:na] at jcifs.smb.SmbFile.open0(SmbFile.java:989) ~[jcifs-1.3.17.jar:na] at jcifs.smb.SmbFile.open(SmbFile.java:1006) ~[jcifs-1.3.17.jar:na] at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:73) ~[jcifs-1.3.17.jar:na] at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:65) ~[jcifs-1.3.17.jar:na] at jcifs.smb.SmbFile.getInputStream(SmbFile.java:2844) ~[jcifs-1.3.17.jar:na] ``` It seems that there is some kind of limitation or setting in JCIFS that causes this problem. Here is some test code reproduce the problem: ``` for (int i = 0; i < 20000; i++) { try { SmbFile smbFile = new SmbFile("smb://fileserver/share/image.jpg", auth); byte[] data = IOUtils.toByteArray(smbFile.getInputStream()); System.out.println(smbFile.getPath() + " " + data.length); } catch (SmbException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } ``` We've checked the error logs on the file server but there is nothing to see so we assume that we are doing something wrong or there is something in JCIFS we have to configure properly.