9

I upgraded Azure Cosmos DB Emulator from version 1.22 to 2.0. Now when I go to the local Data Explorer, nothing loads in the Explorer tab and I see error

Failed to get authorization headers for offers: {"readyState":4,"responseText":"{\"code\":\"InternalServerError\",\"message\":\"Unknown server error occurred when processing this request.\r\nActivityId: 48afdb03-e04b-4a5e-b568-e268c32eb10f, Microsoft.Azure.Documents.Common/2.0.0.0\"}","responseJSON":{"code":"InternalServerError","message":"Unknown server error occurred when processing this request.\r\nActivityId: 48afdb03-e04b-4a5e-b568-e268c32eb10f, Microsoft.Azure.Documents.Common/2.0.0.0"},"status":500,"statusText":"error"}

I have tried reinstalling it, restarting the PC, and running it as an administrator.

What can I do to fix this?

Matt
  • 25,467
  • 18
  • 120
  • 187
Scotty H
  • 6,432
  • 6
  • 41
  • 94

2 Answers2

10

It looks like 2.0.0 CosmosDB Emulator requires you to reset the data that's in it. That's the only thing that fixed it for me.

You can do that from the CosmosDB emulator icon

enter image description here

Once you reset, it will work. Also keep in mind that pre 2.0 SDKs won't work on the new emulator.

Nick Chapsas
  • 6,872
  • 1
  • 20
  • 29
  • Didn't help in my case. The Emulator worked fine for days until it stopped working suddenly with the error shown in the question. Reset Data and even uninstalling/reinstalling did not help. Do you have any idea how to fix this, please? – Matt Jan 23 '19 at 08:50
  • **Update:** I've manually deleted CosmosDbEmulator directory in AppData\Local, rebooted, and now it works again. But that means that you lose your data. Is there another way to reset it to a working state? – Matt Jan 23 '19 at 09:02
  • @Matt None that I know. The emulator is clearly not for anything else other than dev work so it shouldn't be a problem. – Nick Chapsas Jan 23 '19 at 09:12
  • Yes I know it's for development only. But even then it is not nice having to start with empty databases again. I tried to store some data in .json files and upload them via the Emulator's upload function, but that didn't work either. If that would work then it would be easier to restore the test data used for developing. If you have experience with that, could you update your answer to show a way how to backup/restore test data in the emulator? – Matt Jan 23 '19 at 10:16
3

In my case, I had to uninstall / reinstall the emulator (you can download it from https://aka.ms/cosmosdb-emulator), then after a reboot I did a "Reset data..." in the emulator's context menu (as described by Nick), and afterwards it was working again.

Resetting the data alone did not do the trick in my case.

I found the following way to get it working again (Emulator Version 2.1.4.0 on Windows 10 Enterprise - Build 1803):

  1. Start the emulator so you're getting a systray icon. Wait until you get "Emulator started" message. Check after startup if the Emulator explorer is working. If it hangs (showing three dots animation forever), continue with step 2.
  2. Reset data: Via Systray, right click, context menu, select "Reset data...". Wait until the emulator came up ("Emulator started"). Continue with step 3.
  3. Shutdown the Emulator: Via Systray, right click, context menu, select "Exit"
  4. Reboot your PC
  5. After reboot, start the emulator (go to 1.). Now the Emulator explorer should work (you can create a collection via "New collection" to test it).

Notes:

  • "Reset data..." deletes the local Cosmos DB Emulator folder, then it stops and restarts the emulator service.

  • it seem to be important to start it before you start any VPN connection (e.g. the firm's VPN) - The emulator depends on the RegisteredIO APIs in addition to regular Winsockets so there can be undesired side effects with 3rd party software.

  • if you run the emulator on a laptop, it is recommended that you stop it before your computer enters sleep/hibernate mode. This is to ensure that the emulator’s data remains consistent and prevent you from resetting it often.

  • Since version 2.2.1, there is a new command line option /disablerio that will switch the emulator to work with regular Winsockets APIs. If you encounter any issues with VPNs or 3rd party software, you can try this switch. In a command prompt (admin shell), type:
    cd /d "%ProgramFiles%\Azure Cosmos DB Emulator"
    CosmosDB.Emulator.exe /disablerio

  • if you run into connect issues, check the CosmosDB emulator's SSL certificates.


Some details about the emulator

This is the directory the emulator is using:

C:\Users\[userid]\AppData\Local\CosmosDBEmulator

The application itself can be found here:

C:\Program Files\Azure Cosmos DB Emulator\Microsoft.Azure.Cosmos.Emulator.exe

While the emulator itself doesn't have many config options, there are 3 config files in the directory mentioned above: ComputeMachine.Config, Machine.Config and GatewayMachine.Config.

The CosmosDB team can help if you enable the trace log. Do the following:

To collect debugging traces, run the following commands from an administrative command prompt:

  1. cd /d "%ProgramFiles%\Azure Cosmos DB Emulator"
  2. CosmosDB.Emulator.exe /shutdown. Watch the system tray to make sure the program has shut down, it may take a minute. You can also just click Exit in the Azure Cosmos DB Emulator user interface.
  3. CosmosDB.Emulator.exe /starttraces
  4. CosmosDB.Emulator.exe
  5. Reproduce the problem. If Data Explorer is not working, you only need to wait for the browser to open for a few seconds to catch the error.
  6. CosmosDB.Emulator.exe /stoptraces
  7. Navigate to %ProgramFiles%\Azure Cosmos DB Emulator and find the docdbemulator_000001.etl file.
  8. Send the .etl file along with repro steps to askcosmosdb@microsoft.com for debugging.

Update: I got response from the CosmosDB dev team, which I've included in this answer. Please let me also know via comments below this answer if you found out something. Let me note that usually this tool, which I use very often for developing CosmosDB solutions, is working fine.

Matt
  • 25,467
  • 18
  • 120
  • 187