question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GetScopeInfoAsync Internal Server Error

See original GitHub issue

Hello, I try to implement the multiple scopes migration. But when I try to use RemoteOrchestrator.GetScopeInfoAsync I get a internal server error.

Code-Client

var scopeMigration = await GetScopeNameAsync(_configScope, agentConfig);
s1 = await agentConfig.SynchronizeAsync(scopeMigration.OldScopeName, parameters, _progress);
_logger.LogInformation(4810, "Sync Config Result: {Result}", s1);

if (scopeMigration.IsNew)
{
	var serverScopeInfo = await agentConfig.RemoteOrchestrator.GetScopeInfoAsync(scopeMigration.NewScopeName);
	var newScopeInfo = await agentConfig.LocalOrchestrator.ProvisionAsync(serverScopeInfo);

	var newScopeInfoClient = await agentConfig.LocalOrchestrator.GetScopeInfoClientAsync(newScopeInfo.Name);
	var oldScopeInfoClient = await agentConfig.LocalOrchestrator.GetScopeInfoClientAsync(scopeMigration.OldScopeName);

	newScopeInfoClient.ShadowScope(oldScopeInfoClient);
	await agentConfig.LocalOrchestrator.SaveScopeInfoClientAsync(newScopeInfoClient);
}

Code-Server

/// <summary>
/// This POST handler is mandatory to handle all the sync process
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task Post()
{
	try
	{
		var scopeName = HttpContext.GetScopeName();

		var webserverAgent = webserverAgents.FirstOrDefault(c => c.ScopeName == scopeName);

		await webserverAgent.HandleRequestAsync(HttpContext).ConfigureAwait(false);
	}
	catch (Exception ex)
	{
		_logger.LogError(ex, ex.Message);
		throw;
	}
}

Error

2022-10-28 08:32:56.237 +02:00 [ERR] An unhandled exception has occurred while executing the request.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Random.DatabaseSync.Controllers.SyncController.Post()
   at lambda_method4(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
2022-10-28 08:32:56.241 +02:00 [WRN] No exception handler was found, rethrowing original exception.
2022-10-28 08:32:56.241 +02:00 [ERR] Connection ID "18014398511092611197", Request ID "80003881-0000-fa00-b63f-84710c7967bb": An unhandled exception was thrown by the application.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Random.DatabaseSync.Controllers.SyncController.Post()
   at lambda_method4(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()
2022-10-28 08:32:56.243 +02:00 [INF] Request finished HTTP/1.1 POST http://10.0.0.92:8004/api/sync/ application/json 86 - 500 - - 22.4363ms
2022-10-28 08:32:56.781 +02:00 [INF] Request starting HTTP/1.1 POST http://10.0.0.92:8004/api/sync/ application/json 86
2022-10-28 08:32:56.781 +02:00 [INF] Executing endpoint 'Random.DatabaseSync.Controllers.SyncController.Post (Random.DatabaseSync)'
2022-10-28 08:32:56.781 +02:00 [INF] Route matched with {action = "Post", controller = "Sync"}. Executing controller action with signature System.Threading.Tasks.Task Post() on controller Random.DatabaseSync.Controllers.SyncController (Random.DatabaseSync).
2022-10-28 08:32:56.781 +02:00 [ERR] Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Random.DatabaseSync.Controllers.SyncController.Post()
2022-10-28 08:32:56.782 +02:00 [INF] Executed action Random.DatabaseSync.Controllers.SyncController.Post (Random.DatabaseSync) in 0.8425ms
2022-10-28 08:32:56.782 +02:00 [INF] Executed endpoint 'Random.DatabaseSync.Controllers.SyncController.Post (Random.DatabaseSync)'
2022-10-28 08:32:56.782 +02:00 [ERR] An unhandled exception has occurred while executing the request.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Random.DatabaseSync.Controllers.SyncController.Post()
   at lambda_method4(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
2022-10-28 08:32:56.783 +02:00 [WRN] No exception handler was found, rethrowing original exception.
2022-10-28 08:32:56.783 +02:00 [ERR] Connection ID "18014398511092611197", Request ID "80003882-0000-fa00-b63f-84710c7967bb": An unhandled exception was thrown by the application.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Random.DatabaseSync.Controllers.SyncController.Post()
   at lambda_method4(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()
2022-10-28 08:32:56.784 +02:00 [INF] Request finished HTTP/1.1 POST http://10.0.0.92:8004/api/sync/ application/json 86 - 500 - - 2.9724ms

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
BluePalmTreecommented, Nov 3, 2022

Sure.

In the Startup.cs you have to add the line:

services.AddMemoryCache();

And this is the code for the controller action:

public SyncController(IConfiguration configuration,
					  IEnumerable<WebServerAgent> webServerAgents,
					  ILogger<SyncController> logger,
					  IMemoryCache memoryCache)
{
	_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
	_logger = logger ?? throw new ArgumentNullException(nameof(logger));
	_memoryCache = memoryCache ?? throw new ArgumentNullException(nameof(memoryCache));

	this.webserverAgents = webServerAgents ?? throw new ArgumentNullException(nameof(webServerAgents));
}

[HttpPost]
public async Task Post()
{
	try
	{
		var scopeName = HttpContext.GetScopeName();

		var webserverAgent = webserverAgents.FirstOrDefault(c => c.ScopeName == scopeName);

		if (webserverAgent == null)
		{
			if (!_memoryCache.TryGetValue(scopeName, out webserverAgent))
			{
				var connectionString = _configuration.GetConnectionString("DefaultConnection");
				var syncOptions = _configuration.GetSection("SyncOptions");
				var snapshotDirectory = syncOptions.GetValue<string>("SnapshotDirectory");
				var snapshotBatchSize = syncOptions.GetValue<int>("SnapshotBatchsize");

				var options = new SyncOptions
				{
					BatchSize = snapshotBatchSize
				};

				if (!string.IsNullOrWhiteSpace(snapshotDirectory))
				{
					options.SnapshotsDirectory = snapshotDirectory;
				}

				var serverProvider = new SqlSyncChangeTrackingProvider(connectionString);
				var remoteOrchestrator = new RemoteOrchestrator(serverProvider);
				var scopeInfo = await remoteOrchestrator.GetScopeInfoAsync(scopeName).ConfigureAwait(false);
				webserverAgent = new WebServerAgent(serverProvider, scopeInfo.Setup, options, null, scopeInfo.Name);

				_memoryCache.Set(scopeName, webserverAgent, new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(90)));
			}
		}

		await webserverAgent.HandleRequestAsync(HttpContext).ConfigureAwait(false);
	}
	catch (Exception ex)
	{
		_logger.LogError(ex, ex.Message);
		throw;
	}
}
0reactions
Mimetiscommented, Nov 3, 2022

thanks awesome work !!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't create a SqlRecord based on the rows we have: ...
I have a download only sync operation from Server to server client DBs. One of the DB sync failed with this error Encountered...
Read more >
How do i solve 500 internal server error if problem is on ...
Have that user try logging in with a private browser/incognito. Typically a 500 error is on the server side and not the client...
Read more >
tidb ddl 源码 - seaxiang
GetScope (status string) variable.ScopeFlag // Stop stops DDL worker. Stop() error // RegisterStatsHandle registers statistics handle and its ...
Read more >
Getting "HTTP Status 500 – Internal Server Error ... - QuickBooks
Getting "HTTP Status 500 – Internal Server Error" error message when trying to setup payroll in Quickbooks online. Any ideas?
Read more >
TIDB 部分核心数据结构
RecordSet, error) // Execute a sql statement. ... InfoSyncer stores server info to etcd when the tidb-server starts and ... info *infosync.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found