Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminate app after upload send #101

Open
ivanscm opened this issue Mar 28, 2018 · 4 comments
Open

Terminate app after upload send #101

ivanscm opened this issue Mar 28, 2018 · 4 comments

Comments

@ivanscm
Copy link

ivanscm commented Mar 28, 2018

DEFAULT_FILE_STORAGE = 'swift.storage.SwiftStorage'
SWIFT_AUTH_URL = 'https://auth.selcdn.ru/v1'
SWIFT_USERNAME = 'dn'
SWIFT_PASSWORD = 'dd'
SWIFT_CONTAINER_NAME = 'media'
SWIFT_STATIC_BASE_URL = None

model
photo = models.ImageField(upload_to='')
and form
photo = forms.ImageField()
and view

form = AboutPageEditForm(request.POST, request.FILES)
        if form.is_valid():
            about_page = AboutPage(photo=request.FILES['photo'])
            about_page.save()

file success upload, db row add, app terminate moment

windows 7x64
django-storage-swift==1.2.18
python 3.6.

@KostyaEsmukov
Copy link
Contributor

I don't understand the problem at all, to be honest, but I'm Russian and I might try to help you if you email me a detailed problem description (possibly in Russian). This looks like a question rather than a bug report for me.

BTW For Selectel I strongly suggest to set SWIFT_AUTH_TOKEN_DURATION to a low value, like 1 hr (3600), because Selectel doesn't create tokens for a fixed amount of time. Instead, they send back a token lifetime in the X-Expire-Auth-Token header. According to my observations a newly acquired token lifetime ranges from 5 to 13 hrs, but that seems completely random. We tried to ask them to fix this issue on their side, but they refused to do anything about it, unfortunately.

@einarf
Copy link
Contributor

einarf commented Mar 28, 2018

Does the backend actually re-authenticate now if the token is expired? That did not used to be the case.

@KostyaEsmukov
Copy link
Contributor

Uhm... Ok, I see that since 1.2.18 auth token is handled by swiftclient instead. So for now, I believe, SWIFT_AUTH_TOKEN_DURATION won't do anything at all (its value is not even referenced in the code). I don't know how swiftclient handles expired tokens, so I can't say if this is still the case for the latest versions. What I was describing was correct for version 1.2.17.

At 1.2.17 the package was re-authenticating after SWIFT_AUTH_TOKEN_DURATION seconds since previous token creation. If the token expired before that time (i.e. object storage stopped accepting it), you were getting exceptions until SWIFT_AUTH_TOKEN_DURATION seconds since token creation have passed. And what I was suggesting is to set this value low enough to minimize the risk of having that period of time when token is already expired but SWIFT_AUTH_TOKEN_DURATION seconds haven't passed yet.

@KostyaEsmukov
Copy link
Contributor

@ivanscm contacted me over email and it seems that he was able to solve his issue.

The problem was that after uploading a file, a python process (the runserver manage command for local development) was silently crashing. It turns out that the reason was in the wrong version of libmagic being installed: https://stackoverflow.com/questions/41516138/python-magic-installation-challenges-for-64-bit-windows-10-running-32-bit-python/48790592

Regarding my concern about the token lifetime: I'd suggest to leave it for now until someone else would raise this problem again (feel free to ping me), because I'm currently neither able to check the latest version nor I'm really interested in that.

I think this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants