Backup to URL Hangs on PREEMPTIVE_HTTP_EVENT_WAIT in an Azure VM

Backup to URL hangs on PREEMPTIVE_HTTP_EVENT_WAIT when an outbound rule blocks the internet. I saw this while playing with SQL Server on an Azure virtual machine. I had created an outbound rule to avoid internet access. Then my backups started to give me trouble.

Gouache painting of a tall stone wall with one small round vermilion hatch and a wicker basket on a rope pulley waiting beside it

The Error

The backup ran for around 20 minutes, and then it failed with this message:

Msg 3201, Level 16, State 1, Line 1
Cannot open backup device 'https://sqlauthority.blob.core.windows.net/backupcontainer/SQLAuthDB.bak'. Operating system error 50(The request is not supported.).
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.

What Happened

For learning, I wanted to block internet access on my SQL Server virtual machine in Azure. So I created an outbound rule that blocks the internet with the Deny option, as shown here.

Azure outbound port rules for a network security group: a rule named BlockInternet at priority 200, destination Internet, action Deny, highlighted, above the default AllowVnetOutBound rule

The rule worked and I got what I wanted. I couldn’t open any site, including google.com.

Browser window for https://www.google.co.in showing the message: This page can't be displayed

Then my backups to URL stopped working. A backup that used to finish in a few seconds now ran for a long time. This is the backup command:

BACKUP DATABASE SQLAuthDB TO  
URL = N'https://sqlauthority.blob.core.windows.net/backupcontainer/SQLAuthDB.bak'
GO

Why It Happens

I couldn’t find any documentation for PREEMPTIVE_HTTP_EVENT_WAIT. From the name, it looks like a wait that won’t end by itself the way normal SQL threads do. It also looks like it’s waiting for an HTTP request that went out to storage for my backup.

A backup to URL leaves the machine, so it needs the internet. That is the thing I had blocked. I wondered whether this meant the VM must have internet access, or whether there was something else I could do.

How to Check

I queried sys.sysprocesses for the backup session, which was SPID 58. It returned two rows with two wait types:

  • BACKUPTHREAD
  • PREEMPTIVE_HTTP_EVENT_WAIT

SSMS query on sys.sysprocesses for spid 58 with two result rows: one suspended with last wait type BACKUPTHREAD and one runnable with last wait type PREEMPTIVE_HTTP_EVENT_WAIT, both with wait times over 187000

The Fix

From my search on the internet, I found two ways to fix this and keep the existing rule:

  1. Open the specific port, with a rule priority that beats the internet rule. Here the backup uses https, which uses port 443.
  2. Add an outbound rule for storage, so connections to storage go out even though the internet is blocked.

Option 2 is better, because it takes care of the port number automatically. I set the internet rule priority to 200 and added a new rule with the destination set to Storage.

Azure outbound rules list: AllowedOnlyStorage at priority 100 with destination Storage and action Allow, highlighted, above BlockInternet at priority 200 set to Deny and AllowVnetOutBound at 65000

Confirm It Worked

After this, google.com still didn’t open, but backup to URL started working.

SSMS window with BACKUP DATABASE SQLAuthDB TO URL with STATS = 50 and the Messages tab reporting the backup successfully processed 346 pages in 0.111 seconds

How to Prevent It

If you see PREEMPTIVE_HTTP_EVENT_WAIT, check what kind of query is going out to the internet. If it’s a backup to URL, you know the answer now. When you block the internet on an Azure VM, add the Storage rule first.

Quick reference card: Backup to URL Hangs

A blocked internet is not a broken backup, it is a missing rule for storage.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL Azure, SQL Backup and Restore, SQL Server, SQL Wait Stats
Previous Post
Find the Oldest Query Plan in the Plan Cache
Next Post
SQL SERVER – Small Backup for Large Database

Related Posts

1 Comment. Leave new

  • We are facing the issue of PREEMPTIVE_HTTP_EVENT_WAIT, but we cannot solve it with the firewall settings because our outbound traffic is only allowed via a proxy. I assume that SQL server is not using the proxy when executing the backup to URL command. Is it possible to influence that?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.