Skip to content

Commit

Permalink
Make engine.openGate() async to avoid deadlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
albinowax committed Mar 21, 2019
1 parent 1b6e94a commit 4ef9fce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
6 changes: 0 additions & 6 deletions src/ThreadedRequestEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,9 @@ open class ThreadedRequestEngine(url: String, val threads: Int, maxQueueSize: In
if (req.gate != null) {

val withHold = 5
Utils.out("Starting request")

Utils.callbacks.stdout.write(byteReq, 0, byteReq.size-withHold)
outputstream.write(byteReq, 0, byteReq.size-withHold)
req.gate!!.waitForGo()
Utils.callbacks.stdout.write(byteReq, byteReq.size-withHold, withHold)
outputstream.write(byteReq, byteReq.size-withHold, withHold)
Utils.out("\n...request completed")
//outputstream.write(byteReq.get(byteReq.lastIndex).toInt())
}
else {
outputstream.write(byteReq)
Expand Down
27 changes: 20 additions & 7 deletions src/burp/Floodgate.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,36 @@ public class Floodgate {
final private AtomicBoolean isOpen = new AtomicBoolean(false);

// the python thread will set here
void open() throws InterruptedException {
void open() {
if (isOpen.get()) {
Utils.out("Gate is already open");
return;
}

while (remaining.get() > 0) {
Utils.out("Threads remaining: "+remaining.get());
synchronized (remaining) {
remaining.wait();
}
if (remaining.get() > 0) {
new Thread(() -> {
while (remaining.get() > 0) {
//Utils.out("Threads remaining: "+remaining.get());
synchronized (remaining) {
try {
remaining.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
makeOpen();
}).start();
}
else {
makeOpen();
}
}

private void makeOpen() {
synchronized (isOpen) {
isOpen.set(true);
isOpen.notifyAll();
//Utils.out("Gate opened");
}
}

Expand Down

0 comments on commit 4ef9fce

Please sign in to comment.