Skip to content

Commit af501f4

Browse files
committed
Add wall clock timeout to mpsse_flush()
I think that libusb_handle_events_timeout_completed is supposed to make progress or time out, but sometimes we hit a case where it makes no progress, and mpsse_flush() loops forever. This wall clock timeout kicks it out of that loop. OpenOCD appears to die afterwards, but that's still an improvement. Change-Id: Id9220557625834fb5b7dccf65251651a11a887f0
1 parent 933cb87 commit af501f4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/jtag/drivers/mpsse.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ int mpsse_flush(struct mpsse_ctx *ctx)
892892
}
893893

894894
/* Polling loop, more or less taken from libftdi */
895+
int64_t start = timeval_ms();
895896
while (!write_result.done || !read_result.done) {
896897
struct timeval timeout_usb;
897898

@@ -914,6 +915,11 @@ int mpsse_flush(struct mpsse_ctx *ctx)
914915
break;
915916
}
916917
}
918+
919+
if (timeval_ms() - start > 2000) {
920+
LOG_ERROR("Timed out handling USB events in mpsse_flush().");
921+
break;
922+
}
917923
}
918924

919925
error_check:

0 commit comments

Comments
 (0)