Should a dialog close before a mutating change is accepted?

I have a simple settings dialog

Some setting: [     ]

[Update] [Cancel]

When the user clicks on "Update", the app will send a request to the server to update the user's settings.

Should the dialog close before or after this request is acknowledged? I can think of three different behaviors here, and I'm not sure what's best:

  1. The dialog stays open until the server responds with success (in which case the dialog closes) or failure (in which case the error is reported). During this time, perhaps the "Update" button turns into a spinner, or some other indication that something's happening.

  2. The dialog immediately closes, and the settings displayed in the main app page are immediately updated client-side. When the server returns, if it returns with a failure, then some notification (popup? error message underneath the settings?) tells the user it failed.

  3. The dialog immediately closes, but the settings on the main app page turn into a spinner, which resolves when the server returns.