File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed
driver-core/src/main/com/mongodb/internal/connection Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -103,17 +103,21 @@ public void write(final List<ByteBuf> buffers) throws IOException {
103
103
@ Override
104
104
public ByteBuf read (final int numBytes ) throws IOException {
105
105
ByteBuf buffer = bufferProvider .getBuffer (numBytes );
106
- int totalBytesRead = 0 ;
107
- byte [] bytes = buffer .array ();
108
- while (totalBytesRead < buffer .limit ()) {
109
- int bytesRead = inputStream .read (bytes , totalBytesRead , buffer .limit () - totalBytesRead );
110
- if (bytesRead == -1 ) {
111
- buffer .release ();
112
- throw new MongoSocketReadException ("Prematurely reached end of stream" , getAddress ());
106
+ try {
107
+ int totalBytesRead = 0 ;
108
+ byte [] bytes = buffer .array ();
109
+ while (totalBytesRead < buffer .limit ()) {
110
+ int bytesRead = inputStream .read (bytes , totalBytesRead , buffer .limit () - totalBytesRead );
111
+ if (bytesRead == -1 ) {
112
+ throw new MongoSocketReadException ("Prematurely reached end of stream" , getAddress ());
113
+ }
114
+ totalBytesRead += bytesRead ;
113
115
}
114
- totalBytesRead += bytesRead ;
116
+ return buffer ;
117
+ } catch (Exception e ) {
118
+ buffer .release ();
119
+ throw e ;
115
120
}
116
- return buffer ;
117
121
}
118
122
119
123
@ Override
You can’t perform that action at this time.
0 commit comments