Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 2f952a3

Browse files
committed
debug and add mutex for halding requiests
1 parent 39b1fce commit 2f952a3

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

owncloudComLibrary/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies {
1212
implementation("com.squareup.moshi:moshi-kotlin:$moshiVersion") {
1313
exclude module: "kotlin-reflect"
1414
}
15+
implementation 'org.apache.commons:commons-lang3:3.12.0'
1516
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion"
1617

1718
testImplementation 'junit:junit:4.13.2'

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.accounts.AccountManager;
2929
import android.accounts.AccountsException;
3030
import android.net.Uri;
31+
import android.util.Log;
3132

3233
import at.bitfire.dav4jvm.exception.HttpException;
3334
import com.owncloud.android.lib.common.accounts.AccountUtils;
@@ -42,6 +43,7 @@
4243
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
4344
import okhttp3.Cookie;
4445
import okhttp3.HttpUrl;
46+
import org.apache.commons.lang3.exception.ExceptionUtils;
4547
import timber.log.Timber;
4648

4749
import java.io.IOException;
@@ -69,6 +71,8 @@ public class OwnCloudClient extends HttpClient {
6971
private OwnCloudAccount mAccount;
7072
private ConnectionValidator mConnectionValidator;
7173

74+
private static Boolean mHoldRequests = false;
75+
7276
private SingleSessionManager mSingleSessionManager = null;
7377

7478
private boolean mFollowRedirects;
@@ -109,7 +113,41 @@ public int executeHttpMethod(HttpBaseMethod method) throws Exception {
109113
if (mCredentials.getHeaderAuth() != null && method.getRequestHeader(AUTHORIZATION_HEADER) == null) {
110114
method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
111115
}
112-
status = method.execute();
116+
synchronized (mHoldRequests) {
117+
while (mHoldRequests) {
118+
while (true) {
119+
try {
120+
((String) null).toString();
121+
} catch (Exception e) {
122+
Log.d("+++++++",
123+
"HATL BEFORE" +
124+
"\nThread: " + Thread.currentThread().getName() +
125+
"\nobject: " + this.toString() +
126+
"\nMethod: " + method.getHttpUrl() +
127+
"\ntrace: " + ExceptionUtils.getStackTrace(e));
128+
}
129+
Thread.sleep(40000);
130+
}
131+
}
132+
status = method.execute();
133+
if (status == 302) {
134+
mHoldRequests = true;
135+
while (mHoldRequests) {
136+
try {
137+
((String) null).toString();
138+
} catch (Exception e) {
139+
Log.d("+++++++",
140+
"HALT AFTER" +
141+
"\nresponsecode: " + Integer.toString(status) +
142+
"\nThread: " + Thread.currentThread().getName() +
143+
"\nobject: " + this.toString() +
144+
"\nMethod: " + method.getHttpUrl() +
145+
"\ntrace: " + ExceptionUtils.getStackTrace(e));
146+
}
147+
Thread.sleep(40000);
148+
}
149+
}
150+
}
113151

114152
if (mFollowRedirects) {
115153
status = followRedirection(method).getLastStatus();
@@ -171,7 +209,7 @@ public RedirectionPath followRedirection(HttpBaseMethod method) throws Exception
171209

172210
redirectionPath.addLocation(location);
173211

174-
// Release the connection to avoid reach the max number of connections per host
212+
// Release the connection to avoid reach the max number of connections per hostClientManager
175213
// due to it will be set a different url
176214
exhaustResponse(method.getResponseBodyAsStream());
177215

0 commit comments

Comments
 (0)