-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[jni] Deadlock when calling Interceptor.Chain.proceed()
via bindings of Kotlin Package: OkHttp
#1337
Comments
Basically if we're calling another callback on the same thread while hopping to another thread, it causes a deadlock. For example, here we're recursively calling the same function but hopping from another thread: late final StringConverter stringConverter;
stringConverter = StringConverter.implement($StringConverterImpl(
parseToInt: (s) {
final num = int.parse(s.toDartString(releaseOriginal: true));
if (num > 0) {
return StringConverterConsumer.consumeOnAnotherThreadAndLock(
stringConverter,
'${num - 1}'.toJString(),
).intValue() +
1;
}
return 0;
},
));
StringConverterConsumer.consumeOnAnotherThreadAndLock(
stringConverter,
'5'.toJString(),
); Java code: public interface StringConverter {
int parseToInt(String s) throws StringConversionException;
}
public class StringConverterConsumer {
public static Integer consumeOnSameThread(StringConverter stringConverter, String s) {
try {
return stringConverter.parseToInt(s);
} catch (StringConversionException e) {
return -1;
}
}
public static Integer consumeOnAnotherThreadAndLock(StringConverter stringConverter, String s) {
var futureTask = new FutureTask<>(() -> {
return consumeOnSameThread(stringConverter, s);
});
new Thread(futureTask).start();
try {
return futureTask.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
} |
I don't really have enough context here. How those this problem arise? Why does the Java code have What use case causes this? |
OkHttp has a mechanism where you create request interceptors that get a
Yeah this is not ideal. For example we could have a redirect interceptor that handles http redirects, and there could be a lot of them. I think we want to have a way to signal giving up control of the current function to be able to do something else and come back to this. Maybe we could use the existing |
This is a very specific issue faced while implementing the
Interceptor
interface inpackage: ok_http
. The actual cause of this deadlock is yet to be found, (by a replica of Interceptor, as planned.)Creating this issue to reference in PR and files: dart-lang/http#1257, to track the status.
cc: @HosseinYousefi
The text was updated successfully, but these errors were encountered: