Skip to content

Relogin issue? #125

@HarelM

Description

@HarelM

We have seen the following issue in our server logs - a failure to relogin basically (according to the stack trace).

Here's the stack trace:

---> WikiClientLibrary.OperationFailedException: Failed: Unable to continue login. Your session most likely timed out.
--
  | at WikiClientLibrary.Sites.WikiSite.LoginAsync(String userName, String password, String domain, CancellationToken cancellationToken)
  | at IsraelHiking.DataAccess.LoginAgainAccountAssertionFailureHandler.Login(WikiSite site) in /net/IsraelHiking.DataAccess/WikimediaCommonGateway.cs:line 32   at IsraelHiking.DataAccess.LoginAgainAccountAssertionFailureHandler.Login(WikiSite site) in /net/IsraelHiking.DataAccess/WikimediaCommonGateway.cs:line 32
  | at WikiClientLibrary.Sites.WikiSite.Relogin()   at WikiClientLibrary.Sites.WikiSite.Relogin()
  | at WikiClientLibrary.Sites.WikiSite.InvokeMediaWikiApiAsync[T](WikiRequestMessage message, IWikiResponseMessageParser`1 responseParser, Boolean suppressAccountAssertion, CancellationToken cancellationToken)   at WikiClientLibrary.Sites.WikiSite.InvokeMediaWikiApiAsync[T](WikiRequestMessage message, IWikiResponseMessageParser`1 responseParser, Boolean suppressAccountAssertion, CancellationToken cancellationToken)
  | at WikiClientLibrary.RequestHelper.RefreshPagesAsync(IEnumerable`1 pages, IWikiPageQueryProvider options, CancellationToken cancellationToken)   at WikiClientLibrary.RequestHelper.RefreshPagesAsync(IEnumerable`1 pages, IWikiPageQueryProvider options, CancellationToken cancellationToken)

The code that we are using is the following basically (for relogin):

internal class LoginAgainAccountAssertionFailureHandler : IAccountAssertionFailureHandler
{

    private readonly NonPublicConfigurationData _options;

    public LoginAgainAccountAssertionFailureHandler(NonPublicConfigurationData options)
    {
        _options = options;
    }

    public async Task<bool> Login(WikiSite site)
    {
        await site.LoginAsync(_options.WikiMediaUserName, _options.WikiMediaPassword);
        return true;
    }
}

And in the gateway class (the service which we initialize when the server code starts):

public async Task Initialize()
    {
        var wikiClient = new WikiClient
        {
            ClientUserAgent = Branding.USER_AGENT,
            Timeout = new TimeSpan(0, 5, 0) // allow large images upload
        };

        _site = new WikiSite(wikiClient, new SiteOptions(BASE_API_ADDRESS));
        await _site.Initialization;
        await _site.LoginAsync(_options.WikiMediaUserName, _options.WikiMediaPassword);
        _site.AccountAssertionFailureHandler = new LoginAgainAccountAssertionFailureHandler(_options);
        _logger.LogInformation("Finished initializing Wikimedia common service");
    }

The above issue is seen when we try to invoke upload image call:

public async Task<string> UploadImage(string fileName, string description, string author, Stream contentStream, Coordinate location)
    {
        _logger.LogInformation($"Upload an image to wikimedia common. File name: {fileName}, Location: {location.Y}, {location.X}");
        var wikiFileName = GetNonExistingFilePageName(fileName);
        var comment = CreateWikipediaComment(location, description, author);
        await _site.GetTokenAsync("edit", true);
        var results = await _site.UploadAsync(wikiFileName, new StreamUploadSource(contentStream), comment, true).ConfigureAwait(false);
        if (results.ResultCode != UploadResultCode.Success)
        {
            throw new Exception("Unable to upload the file\n" + string.Join("\n", results.Warnings.Select(kvp => kvp.Key + ": " + kvp.Value)));
        }
        if (results.Warnings.Any(kvp => kvp.Key == "badfilename"))
        {
            var correctWikiFileName = results.Warnings.First(kvp => kvp.Key == "badfilename").Value;
            _logger.LogWarning($"Received bad file name from wikipedia. old: {wikiFileName}, correct: File:{correctWikiFileName}");
            wikiFileName = "File:" + correctWikiFileName;
        }
        _logger.LogInformation($"Finished uploading image successfully. FileName: {fileName}, wikipage: {wikiFileName}");
        return wikiFileName;
    }

Code can be found here if you would like to see the entire file:
https://github.com/IsraelHikingMap/Site/blob/49ecea0f6e4a0c5e258c3124883ead422f0793b5/IsraelHiking.DataAccess/WikimediaCommonGateway.cs

Let me know if there's anything we can try out to solve this, as I think we are using the library as intended and this should work.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions