Q:

Is it possible to trash an Azure role host and get it started on the same host without cleanup?

Suppose my Azure role creates a lot of temporary files in Windows temporary folder and forgets to delete them. At some point it will receive "can't create temporary file" error. Suppose that once that happens my role code throws an exception out of RoleEntryPoint.Run() and the role is restarted.
I'm not talking about perfect Azure aware code here. My role might use third-party black box code that would now nothing about Azure and "local storage" and would just call System.IO.Path.GetTempPath() and thus create files right in some not Azure friendly location.
The problem is that if the role is started on the very same host and the temporary folder is not cleaned up by some third party the folder is still full of files and the role will be unable to function. According to this answer it might happen that local changes are preserved for my role which is a huge problem in the above scenario.
Are local changes like created temporary files guaranteed to be reset when a role is restarted? How do I ensure that the started role is in reasonably clean state?

A:

The role gets reset on new deployments, upgrades, and newly scaled instances from the golden image (base guest OS vhd).  Generally for reboots and crashes, you get the same VHD and machine.  
The code you write will not have permission to write to the OS drive (D:) - without elevation that is (or logging in via RDP to do this).  Further, there is a quota on the user's role root drive (E:) that will prevent you from accidentally filling the drive with files.  This used to be 10% of the package size was all you were allowed to write.  There is also a quota on the resource drive (C:), but that is much more generous and depends on VM size.
Nothing will be cleaned up on non-local resource drives but you will eventually get errors if you try to exceed quotas.  You can turn off sticky storage on local resources and they will be cleaned up on reboot.  Of course, like other changes to the disk, these non-local resource temp files will occasionally be lost when the guest OS is upgraded (or underlying root OS).  If you are running elevated and really screw up your installation (which you can do), you will need to hit the "Reimage" button on the portal and it will all go back to the golden image.

