GSM shield hangs when reset/uploading code during GPRS connection

EMERG_OFF pin must be connected if GPRS is activated on remote sites!
I just encountered the problem on a remote unit that used the new secure shutdown-code. I did another search and came upon this Application Note from Quactel: http://www.meraprojekt.com.pl/files/quectel/GSM_TCPIP_AN_V1.1.pdf

5.5.
Deactivate PDP context
Use AT+QIDEACT command to deactivate current PDP context.

AT+QIDEACT
//
If the context will not be used in a long period (for example more than one hour), it?s recommended to close this context by command AT+QIDEACT. Normally the response time for this command is about 2-5 seconds. But when the network is very bad or in some abnormal conditions, the longest waiting time will achieve about 2.5 minutes. It?s recommended to set timeout value which is less than 1 minute or less according to their applications. If it is timeout, users have not received DEACT OK, user can restart the module by EMERG_OFF pin.

My €0.02 on this is that at some locations this will never happen ( I have one unit up for a week now out in a field), but on some this will be frequent and completely lock the GSM-shield (8 hours and ~20 gprs connections after installation in another field, it locked)

This is my code and solution (after having issued a shutdown() and waited 12 seconds, then I call this):

void emergency_off() {
  //Connect a 470 ohm resistor between D8 and EMERG_OFF pin of Quectel module. 
  //If signal D8 is high, then module is not powered off. Pull it down for 20 ms to kill module. 
  if (digitalRead(8)) {
    Serial.println("EMERG OFF!");
    delay(12000); //Wait another 12 seconds just in case.
    digitalWrite(8,LOW);
    pinMode(8,OUTPUT);
    delay(30); 
    pinMode(8,INPUT);
  }
}