Sharepoint Client model - request timeout - sharepoint-2010

I am receiving a timeout from the Sharepoint Client Managed Object model.
Microsoft.SharePoint.Client.ServerException: The operation has timed out.
Basically, I am batching 100 updates and sending them at one go. It is no problem for me if takes time but I really want to avoid timeout exception.
I have tried in a million of ways to increase the timeout in the client context but they were all without success. I have used reflection to try to identity what the sharepoint is doing when calling the executequery method of the client context. sharepoint is basically creating an HttpWebRequest and sending it.
I have ended with the below code, but still without success:
public static void SetInfinteTimeout(this ClientContext ctx)
{
int timeout = 10 * 60 * 1000;
ctx.RequestTimeout = timeout;
ctx.PendingRequest.RequestExecutor.RequestKeepAlive = false;
ctx.PendingRequest.RequestExecutor.WebRequest.KeepAlive = false;
ctx.PendingRequest.RequestExecutor.WebRequest.Timeout = timeout;
ctx.PendingRequest.RequestExecutor.WebRequest.ReadWriteTimeout = timeout;
System.Net.ServicePointManager.DefaultConnectionLimit = 200;
System.Net.ServicePointManager.MaxServicePointIdleTime = 2000;
System.Net.ServicePointManager.MaxServicePoints = 1000;
System.Net.ServicePointManager.SetTcpKeepAlive(false, 0, 0);
ServicePointManager.DnsRefreshTimeout = timeout; // 10 minutes
}
But I am still receiving a timeout error!
Is there anything else that I am missing please?
Any assistance would be greatly appreciated.

Have you tried
keeping default KeepAlive (true),
disabling Timeout and
keeping default MaxServicePointIdleTime value (which is 100 seconds by
default but you set to 2).
Just as:
public static void SetInfiniteTimeout(this ClientContext ctx)
{
ctx.RequestTimeout = -1; //ctx.RequestTimeout or System.Threading.Timeout.Infinite;
}
Also, how many seconds it takes for you to get timeout error, in your current configuration?

The solution was to use clientcallablesettings (SPWebApplication.ClientCallableSettings):
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.clientcallablesettings.aspx
This has an execution timeout property and other related settings.
In my case, I needed to add this in the Upgrade Actions as per the below code
using (SPSite site = new SPSite(siteURL))
using (SPWeb web = site.OpenWeb())
{
site.WebApplication.ClientCallableSettings.ExecutionTimeout = TimeSpan.FromMinutes(60);
site.WebApplication.ClientCallableSettings.MaxObjectPaths = 1000;
site.WebApplication.ClientCallableSettings.MaxResourcesPerRequest = 1000;
site.WebApplication.ClientCallableSettings.EnableStackTrace = true;
site.WebApplication.Update();
}

Related

SignalR timeout errors

I have started seeing these errors in the javascript console recently, although using SignalR for a long time. So maybe due to a version update in the client microsoft/signalR
Utils.js:218 [2021-07-28T15:36:22.247Z] Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server.'.
So I added these lines to the client code (commented newly added), this reduced the frequency of the errors, but those did not go away:
connectSignalRHub() {
const liveMarginHub = new SignalR.HubConnectionBuilder()
.withUrl(buildSignalRUrl('liveUpdateHub'))
.withAutomaticReconnect() // newly added
.configureLogging(SignalR.LogLevel.Error)
.build();
// newly added
liveMarginHub.keepAliveIntervalInMilliseconds = 1000 * 60 * 3; // Three minutes
liveMarginHub.serverTimeoutInMilliseconds = 1000 * 60 * 6; // Six minutes
The backend is ASP.NET core. I see there are options of specifying timeouts there as well, like
sc.AddSignalR(c =>
{
c.EnableDetailedErrors = true;
c.ClientTimeoutInterval = TimeSpan.MaxValue;
c.KeepAliveInterval = TimeSpan.MaxValue;
});
But is this a right thing to do? I am just trying to make the timeout error message go away from the UI console.
Thanks

Asp.net core website intermittently refusing connections

I have an asp.net core 3.0 website. It has a controller that implements an HttpGet function that does some database stuff then returns a Json object (https://localhost:44356/api/runner/match).
I have a console application that uses an HttpClient to hit that url. I launch the site locally and then I launch my console app. About 50% of the time it works. The other 50% of the time I get:
HttpRequestException: No connection could be made because the target machine actively refused it.
SocketException: No connection could be made because the target machine actively refused it.
I'm trying to figure out why my console app's connection is being blocked. I don't know how to start debugging this. I tried to implement a retry on the request, but once I get the exception, I keep getting it. So I think it's something non-deterministic happening in my website, potentially related to SSL?
I'm able to hit the url in Chrome locally just fine.
How do I figure out what is blocking the connection from being made?
Is there any chance this is something IIS Express is doing?
Calling code in console app:
static async Task<List<Deck>> GetMatchData()
{
string baseUrl = "https://localhost:44356/api/runner/match";
using (HttpClient client = new HttpClient())
{
HttpResponseMessage res = null;
res = await client.GetAsync(baseUrl);
Controller function:
[HttpGet("match")]
public async Task<ActionResult> GetMatchup()
{
int count = db.Decks.Count();
Random r = new Random();
int d1 = r.Next(count) + 1; // database ids start at 1 for some reason
int d2 = r.Next(count - 1) + 1;
if (d1 == d2)
d2++;
List<Deck> result = new List<Deck>();
result.Add(await db.Decks.FindAsync(d1));
result.Add(await db.Decks.FindAsync(d2));
if (result[0] == null || result[1] == null)
{
return BadRequest();
}
return Ok(result);
}
try
HttpClient httpClient = new HttpClient();
//specify to use TLS 1.2 as default connection
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
string baseUrl = "https://localhost:44356/api/runner/match";
httpClient.BaseAddress = new Uri(baseUrl );
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var getResult = await httpClient.GetAsync(baseUrl);

API progress bar with ASP.NET Core 3.1 and axios

I have long-running ASP.NET Core API that I would like to present a progress bar on UI.
From the server-side, I know how many jobs will be done from the very beginning. Say, if I have 10 jobs and each job takes a second, this will be 10 seconds long progress bar.
The best I could find was https://github.com/DmitrySikorsky/AspNetCoreUploadingProgress, But it relies on saving the progress on Startup. Progress, which is static int. Wouldn't it mean there can be only one upload session at a time in the entire web application?
I wonder if I can do this with axios call:
return axios.post(
'/api/long-running-task',
{},
{
onUploadProgress: function(progressEvent) {
console.log("upload", progressEvent.loaded, progressEvent.total);
},
onDownloadProgress: function(progressEvent) {
console.log("download", progressEvent.loaded, progressEvent.total);
}
}
);
And if I do something properly from ASP.NET Core side, would I be able to communicate back to axios and trigger either onUploadProgress or onDownloadProgress?
What I tried:
[HttpPost]
[Route("long-running-task")]
public async Task<ActionResult> Run()
{
Response.StatusCode = 200;
Response.ContentType = "text/plain";
Response.ContentLength = 10;
var sw = new StreamWriter(Response.Body);
for (var i = 0; i < 10; i++)
{
await Task.Delay(1000);
await sw.WriteAsync("1");
await sw.FlushAsync();
}
return null;
}
axios writes one upload log shortly after, and then one download log 10 seconds later. No interim progress is received.
I found a way to make this work: specify ContentType to be text/event-stream.
I believe it changes server side caching behavior so it should work on any browsers as along as axios is supported. Confirmed working on Chrome 81, Edge 44 and IE 11.
[HttpPost]
[Route("long-running-task")]
public async Task<ActionResult> Run()
{
Response.StatusCode = 200;
Response.ContentType = "text/event-stream";
Response.ContentLength = 10;
var sw = new StreamWriter(Response.Body);
for (var i = 0; i < 10; i++)
{
await Task.Delay(1000);
await sw.WriteAsync("1");
await sw.FlushAsync();
}
return Ok();
}
EDIT: at the end, return Ok() instead of null. If you don't have any jobs, returning null will throw an exception.
Upload and download status wont help you with your task since it will take progress of request size.
What you need to do is on asp.net core side:
Create job/start api which returns you some kind of key
job/progress/id api which will tell you how much you progress
Then inside of your axios call start job get id, then each N seconds call status to see how much your job progressed.
Other option look into signalR steps will be the same the only you wont need to call status api every N seconds you will be able to push back from server you job status.

How to increase max length of acceptable url for ktor?

Now I have ktor server is based on netty.
When I do to long GET request (about 9300 characters (mostly in query params)), ktor answers Unhandled: GET - /bad-request.
If I reduce length of url, it works fine.
In your embedded server config you can provide a function “httpServerCodec” to create HttpServerCodec (https://netty.io/4.1/api/io/netty/handler/codec/http/HttpServerCodec.html) in which you can set the maxInitialLineLength property.
embeddedServer(Netty, configure = {
// Size of the queue to store [ApplicationCall] instances that cannot be immediately processed
requestQueueLimit = 16
// Do not create separate call event group and reuse worker group for processing calls
shareWorkGroup = false
// User-provided function to configure Netty's [ServerBootstrap]
configureBootstrap = {
// ...
}
httpServerCodec = {
HttpServerCodec(.......)
}
// Timeout in seconds for sending responses to client
responseWriteTimeoutSeconds = 10
}) {
// ...
}.start(true)

WCF namedpipe callback timeout exception

I am using WCF for sending and getting data to and from 2 different win form applications running in the same machine. I am using namedpipe and duplexchannel. My client side implementation is shown below.
InstanceContext myContext = new InstanceContext(this);
NetNamedPipeBinding nb = new NetNamedPipeBinding();
nb.MaxBufferPoolSize = 5000000;
nb.MaxBufferSize = 500000;
nb.MaxReceivedMessageSize = 500000;
nb.ReceiveTimeout = TimeSpan.FromMinutes(5);
DuplexChannelFactory<IService> myProxy = new DuplexChannelFactory<IService>(myContext, nb, new EndPointAddress("net.pipe://localhost/MyService"));
IService myServiceClient = myProxy.CreateChannel();
And Server side implementation is shown below:
NetNamedPipeBinding np = new NetNamedPipeBinding();
np.MaxBufferPoolSize = 5000000;
np.MaxBufferSize = 500000;
np.MaxReceivedMessageSize = 500000;
host.AddServiceEndpoint(typeof(IService), np, "net.pipe://localhost/MyService");
host.OpenTimeout = TimeSpan.FromMinutes(5);
host.CloseTimeout = TimeSpan.FromMinutes(5);
host.Open();
I can pass about 100 object collection (ObservableCollection<Customer>) from 1 application through callback to other app. But if I make it 1000 or greater objects, the following Timeout Exception error occurs.
The write to the pipe did not complete
within the allotted timeout of
00:00:00. The time allotted to this
operation may have been a portion of a
longer timeout.
What is the fault in my code ? Please help me to overcome this issue.
Thanks in advance...
Looks like this question was also asked and answered here:
http://social.msdn.microsoft.com/Forums/eu/wcf/thread/38926593-8ea6-481d-8c43-072b73292f6a