@@ -222,22 +222,9 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
222222 while ((list = SimplePipeHelper .getPipeDataList (key )) != null
223223 /* && SimplePipeHelper.isPipeLive(key) */ // check it!
224224 && !writer .checkError ()) {
225- if (!SimplePipeHelper .isPipeLive (key )) {
226- if (System .currentTimeMillis () - lastLiveDetected > waitClosingInterval ) {
227- // break out while loop so pipe connection will be closed
228- break ;
229- } else { // sleep 1s and continue to check pipe status again
230- try {
231- Thread .sleep (1000 );
232- } catch (InterruptedException e ) {
233- }
234- continue ;
235- }
236- } else {
237- lastLiveDetected = System .currentTimeMillis ();
238- }
239225 int size = list .size ();
240226 if (size > 0 ) {
227+ boolean live = SimplePipeHelper .isPipeLive (key );
241228 for (int i = 0 ; i < size ; i ++) {
242229 SimpleSerializable ss = null ;
243230 /*
@@ -249,7 +236,7 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
249236 if (ss == null ) break ; // terminating signal
250237 output (writer , type , key , ss .serialize ());
251238 items ++;
252- if (pipeMaxItemsPerQuery > 0 && items >= pipeMaxItemsPerQuery
239+ if (live && pipeMaxItemsPerQuery > 0 && items >= pipeMaxItemsPerQuery
253240 && !SimplePipeRequest .PIPE_TYPE_CONTINUUM .equals (type )) {
254241 break ;
255242 }
@@ -269,6 +256,20 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
269256 } else {
270257 writer .flush ();
271258 }
259+ if (!SimplePipeHelper .isPipeLive (key )) {
260+ if (System .currentTimeMillis () - lastLiveDetected > waitClosingInterval ) {
261+ // break out while loop so pipe connection will be closed
262+ break ;
263+ } else { // sleep 1s and continue to check pipe status again
264+ try {
265+ Thread .sleep (1000 );
266+ } catch (InterruptedException e ) {
267+ }
268+ continue ;
269+ }
270+ } else {
271+ lastLiveDetected = System .currentTimeMillis ();
272+ }
272273 /*
273274 * Client should send in "notify" request to simulate the following #notifyPipeStatus
274275 */
0 commit comments