Shared context between prompt and ADetailer prompt possible?

Defining something like ${EyeColor=blue} means I can use ${EyeColor} as a variable after that in the prompt just fine, but if I try to access the variable in the ADetailer prompt, I get 'no such variable in context' (paraphrasing, it's been a bit). I'd very much like to have this so I can, specifically, provide details like eye color and facial expression to both prompts without just repeating it.

I'd be interested in this as well!

This is a really essential feature to making this workflow function properly.
As-is, Dynamic Prompts is great and ADetailer is great but they're almost useless combined.

@akx What do you think about storing context variables in a module-scoped variable? That way other extensions can access variables if they want to. There have been previous requests for global variables. We should also share contexts between positive and negative prompts.

@adieyal Sounds icky.
Better store them in the p object in some well-defined way, I think?

In theory I agree with you, except that we don't have any control over it and so it could be brittle. I haven't looked in detail, but if auto1111 doesn't explicitly recognise shared state set by extensions then our variables could easily be wiped - e.g. if the p  object is recreated for some reason.

The p object is not recreated during a single processing operation -- there's been discussions on the a1111 dev discord about formalizing it a bit more (or at least giving it some dict prop for various extensions' data bags), but nothing concrete -- so it should be okay to stash an extra attribute on it.

The other uncertainty is the order in which extensions are run - it's an issue regardless of how we implement it. Do you know if any one is looking into dependencies between extensions or something else the could ensure that an extension will only be run after another one?

At the moment, I can say at least that they happen to be run in alphabetical order, apparently by the name of their extensions directory. That's why I wrote 2 Javascript extensions, one to run before DP and one after, and I even locally renamed Prompt Fusion's directory so it gets run later than usual (seems to have no other important effect...). It would be interesting to have a dependency tree - certainly there are a lot of extensions, and I think the number of current ones grows faster than they become defunct. They have actual dependencies, and formalizing that would stabilize the ecosystem a bit.

Any progress on this?  This seems so essential.  Otherwise, adetailer conflicts with the main prompt and 'muddies' the result.  For instance, if the main prompt dynamically has 'blue eyes' and adetailer dynamically has 'brown eyes', with a denoise of around 50 the eyes end up bluish-brown and not at all like they'd be with consistency.
Even some kind of temporary workaround would be great in the meantime.
Here's the thread on the adetailer github regarding this issue for cross reference: https://github.com/Bing-su/adetailer/issues/62

+1 to this, would also like to see this implemented

+1

It is not straight forward but it should definately be possible by either using global variables or writing to txt.
I got wildcards to work with adetailer with my wildcards fork.
The way prompts are sent to model in gradio makes it hard to comminucate between them in a simple manner.

It is not straight forward but it should definately be possible by either using global variables or writing to txt.
I got wildcards to work with adetailer with my wildcards fork.

Wow, it`s work, thank you! 🔥

It is not straight forward but it should definately be possible by either using global variables or writing to txt. I got wildcards to work with adetailer with my wildcards fork.
The way prompts are sent to model in gradio makes it hard to comminucate between main prompt and adetailer prompt in a simple manner.

Awesome - can't wait to try this!

It is not straight forward but it should definately be possible by either using global variables or writing to txt. I got wildcards to work with adetailer with my wildcards fork.
The way prompts are sent to model in gradio makes it hard to comminucate between main prompt and adetailer prompt in a simple manner.

Awesome - can't wait to try this!

Great, hope you like it.
I am working on some added functionality (specifically working on a special wildcard that simply starts at line 1 of the txt and increases the line by one for every image in a batch, going through each line one by one. It's already sort of functional (using a global variable), but there are some minor issues with it and I'll be gone the weekend so might be sometime next week.
the issue right now is ' resetting'  the global variable at the right time. So it restarts at 1 each batch instead of whereever you left off. Anyway, ill add it to the fork when I think it is functioning properly.

Great, hope you like it.
I am working on some added functionality (specifically working on a special wildcard that simply starts at line 1 of the txt and increases the line by one for every image in a batch, going through each line one by one. It's already sort of functional (using a global variable), but there are some minor issues with it and I'll be gone the weekend so might be sometime next week. the issue right now is ' resetting' the global variable at the right time. So it restarts at 1 each batch instead of whereever you left off. Anyway, ill add it to the fork when I think it is functioning properly.

What are some problems with using a variable? If I stop the generation and start again - the variables are taken completely new.
INFO:sd_dynamic_prompts.dynamic_prompting:Prompt matrix will create 10 images in a total of 10 batches.
 Tested some more, noticed that if nested wildcards inside files - they don't work (words or text files - doesn't matter). The original use of wildcards without "0".
The contents of the file my_test.txt
{red|blue|green} eyes
{purple|brown} eyes
File my_test.txt (in extensions\stable-diffusion-webui-wildcards-adetailer\wildcards folder)
Request __0_my_test__
Result "{purple|brown} eyes" or "{red|blue|green} eyes"

File my_test.txt (in extensions\sd-dynamic-prompts/wildcards folder)
Query __my_test__
Result "blue eyes"/"brown eyes"/"purple eyes"/"red eyes", etc

@uorufu Hmm. Tested some more, noticed that if nested wildcards inside files - they don't work (words or text files - doesn't matter). The original use of wildcards without "0".

Request __0_my_test__
Result "{purple|brown} eyes" or "{red|blue|green} eyes"

Have you tried:
purple|brown
red|blue|green
And then have { eye_color } eyes ?

@uorufu Hmm. Tested some more, noticed that if nested wildcards inside files - they don't work (words or text files - doesn't matter). The original use of wildcards without "0".

Request __0_my_test__
Result "{purple|brown} eyes" or "{red|blue|green} eyes"

Have you tried:
purple|brown red|blue|green
And then have { eye_color } eyes ?

If I change the contents of the file to
red|blue|green
purple|brown
It does not work either through
__0_my_test__ or __my_test__
The result is "purple|brown"

What if you do something like this?
${var=!0_my_test}
[Insert prompt here] { ${var} } eyes

${var=!0_my_test}
[Insert prompt here] { ${var} } eyes

Variables have nothing to do with it. Processing/retrieving nested random values within a file does not work.

${var=!0_my_test}
[Insert prompt here] { ${var} } eyes

Variables have nothing to do with it. Processing/retrieving nested random values within a file does not work.

 I think there was a bug that the order in which things get done are wrong, which I've fixed on my end.

But I've made customizations on my end. I think there was a bug that the order in which things get done are wrong, which I've fixed on my end.

If you changed the script, that makes a difference. What did you change?

But I've made customizations on my end. I think there was a bug that the order in which things get done are wrong, which I've fixed on my end.

If you changed the script, that makes a difference. What did you change?

I didn't change the fork, but the underlying library: https://github.com/adieyal/dynamicprompts
But I didn't use the fork, I used the normal one. I don't see why using the fork should be different in that case. All the templating and replacement is done in that library.

But I've made customizations on my end. I think there was a bug that the order in which things get done are wrong, which I've fixed on my end.

If you changed the script, that makes a difference. What did you change?

I didn't change the fork, but the underlying library: https://github.com/adieyal/dynamicprompts
But I didn't use the fork, I used the normal one. I don't see why using the fork should be different in that case. All the templating and replacement is done in that library.

What did you change in dynamicprompts to make it work?
I need to save the random generation from the base prompt and have the same value used in the adetailer.
I.e. if I have a girl with blue eyes in the base prompt, then blue eyes will be used in the adetailer as well.
If this works for you - I will be glad if you share the solution

What did you change in dynamicprompts to make it work?

I've changed almost everything and added additional functionality. But it doesn't share any information with ADetailer. I've only changed dynamicprompts. I didn't fully understand that your issue only applies if you use the fork.

So in the end do you have variable saving working or not? It's just that this thread is dedicated to that. If you have a solution, please share.
So far a fork that changes wildcards processing is the only working solution for me (https://github.com/uorufu/stable-diffusion-webui-wildcards-adetailer). But it's the only one that doesn't work just the dynamicprompts.

Yes, I have variable sharing implemented in my version. But it's not pretty and requires the dynamicprompts extension at this revsion: 39c06b30409df6259c4430338123f7d4e05d8dc1 (or version 0.29.0). And at that point you can't update this extension anymore, otherwise the changes will get overwritten.
I can make a zip file if you want it.

Nested wildcards don't work, I can maybe look into that next week. But my fork is from wildcards, not dynamic prompts. So it does not have the same functionality.
I literally started programming last week, I though I first tried to get wildcards to work properly with adetailer. Might look into variables later on. Sounds problematic though, considering what I have learned of the process that goes on behind the scenes when automatic1111 prepares the  main promps and adetailer prompts.

Nested wildcards don't work, I can maybe look into that next week. But my fork is from wildcards, not dynamic prompts. So it does not have the same functionality.
I literally started programming last week, I though I first tried to get wildcards to work properly with adetailer. Might look into variables later on. Sounds problematic though, considering what I have learned of the process that goes on behind the scenes when automatic1111 prepares the main promps and adetailer prompts.

That's cool. I'll check it out later. You don't have to leave the dynamic prompts work. The most important thing is to leave the work of nested wildcards. I don't have much programming experience either, but through chatgpt I managed to fix the nested wildcards handling. It is enough to recursively process the selected string in the same way. I can discount the code for a previous version of your fork, it worked. But I think you will make it cleaner and more correct.
I also started to make it possible to process expressions like {test|test2| } and in general it worked, but I stopped at multiple constructions in one line. Don't have time to do that yet either.
You can open a discussion in your fork and we can continue the discussion there. I'll try to look at it next week too.
You can also check out the fork from
https://github.com/sdbds/stable-diffusion-webui-wildcards, you might find it useful.

So in the end do you have variable saving working or not? It's just that this thread is dedicated to that. If you have a solution, please share.
So far a fork that changes wildcards processing is the only working solution for me (https://github.com/uorufu/stable-diffusion-webui-wildcards-adetailer). But it's the only one that doesn't work just the dynamicprompts.

Yes, I have variable sharing implemented in my version as well as some other features like regex variable replacement. But it's not pretty and requires the dynamicprompts extension at this revsion: 39c06b3 (or version 0.29.0). And at that point you can't update this extension anymore, otherwise the changes will get overwritten.
Edit: I've forked it here: https://github.com/Nrgte/dynamicprompts

I'll take a look later and check out the functionality, thanks!

Has anyone had any progress on this without requiring a separate fork or old commit of a1111?
This is truly a necessary feature to make Adetailer mesh with Dynamic Prompts.

Has anyone had any progress on this without requiring a separate fork or old commit of a1111? This is truly a necessary feature to make Adetailer mesh with Dynamic Prompts.

I am not sure this has all the functionality you are looking for, but I made this based on wildcards extension.
https://github.com/uorufu/stable-diffusion-webui-wildcards-adetailer
It's a wildcards extension that uses seed number to calculate the random number. So wildcards in adetailer prompts use the same as the wildcards in the main prompt.
Install by url:
https://github.com/uorufu/stable-diffusion-webui-wildcards-adetailer.git
Works in A1111 as well as Forge.
Functionality:
__0_wildcard__ up to __99_wildcard__ can be used. Wildcards in the same tier use same random number generation (calculates line number based on a float between 0-1, using multiple tiers increases randomization.)
__0_wildcard_10__ locks wildcard on tenth line in wildcard text file. Usefull if you want to test one wildcard line against other wildcard options.
`_$wildcard' iterative wildcard. starts at line 1 and incrementally goes up according to you batchsize. (if the text file has 3 lines and you make a batch of 6, it will go 1-2-3-1-2-3.)
Like I said. The tiers use the same number generation. So if you have to wildcard text files with the same number of lines, for example: wildcardmain.txt and wildcardadetail.txt Then the following is true
Use __5_wildcardmain__ in main prompt and __5_wildcardadetail__ in adetailer prompt and if both text files have say 30 lines and line 12 is randomly chosen, both main and adetail wildcard will choose line 12, as they are both on the same tier/random number generation.
Obviously, don't use _ or $ in wildcard text filenames to avoid issues.

Well this does sound like it's what we need.
But I've tried 20 different methods and can't get it to work.
I'm using A1111 1.10 and all extensions are up to date.
main prompt:
a woman in a ( 0_color dress:1.1) with ( 0_color eyes:1.1), ( 1_color gloves:1.1), wearing ( 1_color shoes:1.1)
adetailer prompt:
( 0_color eyes:1.1), ( 1_color lips:1.1)
In the cmd window I just keep getting results like:
No values found for wildcard '0_color'
No values found for wildcard '0_color'
No values found for wildcard '1_color'
No values found for wildcard '1_color'
[*] Current Seed: 134071013
Am I doing something wrong?
Without the 0_ or 1_ Dynamic Prompts finds the wildcard values fine, but even though the cmd window says the same seed is being used, it doesn't stay consistent.
main prompt: a woman in a ( color dress:1.1) with ( eyecolor eyes:1.1), ( color gloves:1.1), wearing ( eyecolor shoes:1.1)
main prompt output:
a woman in a ( Oxford Brown dress:1.1) with ( yellow eyes:1.1), ( Leaf Green gloves:1.1), wearing ( coral shoes:1.1)
aDetailer prompt 1:
( eyecolor eyes:1.1), ( color lips:1.1)
aDetailer prompt 2:
( color lips:1.1)
cmd output:
[] Current Seed:<PHONE_NUMBER>
[] Current Seed:<PHONE_NUMBER>
[-] ADetailer: applied 1st ad_prompt: '( hazel eyes:1.1), ( Leaf Green lips:1.1)'
[] Current Seed:<PHONE_NUMBER>
[-] ADetailer: applied 2nd ad_prompt: '( Oxford Brown lips:1.1)'
[] Current Seed:<PHONE_NUMBER>
I'm not sure where it's getting 'hazel' from in the first Adetailer prompt output.
It's not just a one-off, either - each time I rerun there's at least one different wildcard thrown into the mix.
If the 0_color and 1_color would lock in the wildcard value anywhere they are used I think this would be solved.

Well this does sound like it's what we need. But I've tried 20 different methods and can't get it to work. I'm using A1111 1.10 and all extensions are up to date.
main prompt: a woman in a ( 0_color dress:1.1) with ( 0_color eyes:1.1), ( 1_color gloves:1.1), wearing ( 1_color shoes:1.1)
adetailer prompt: ( 0_color eyes:1.1), ( 1_color lips:1.1)
In the cmd window I just keep getting results like: No values found for wildcard '0_color' No values found for wildcard '0_color' No values found for wildcard '1_color' No values found for wildcard '1_color' [*] Current Seed: 134071013
Am I doing something wrong?
Without the 0_ or 1_ Dynamic Prompts finds the wildcard values fine, but even though the cmd window says the same seed is being used, it doesn't stay consistent.
main prompt: a woman in a ( color dress:1.1) with ( eyecolor eyes:1.1), ( color gloves:1.1), wearing ( eyecolor shoes:1.1)
main prompt output: a woman in a ( Oxford Brown dress:1.1) with ( yellow eyes:1.1), ( Leaf Green gloves:1.1), wearing ( coral shoes:1.1)
aDetailer prompt 1: ( eyecolor eyes:1.1), ( color lips:1.1)
aDetailer prompt 2: ( color lips:1.1)
cmd output: [] Current Seed:<PHONE_NUMBER> [] Current Seed:<PHONE_NUMBER> [-] ADetailer: applied 1st ad_prompt: '( hazel eyes:1.1), ( Leaf Green lips:1.1)' [] Current Seed:<PHONE_NUMBER> [-] ADetailer: applied 2nd ad_prompt: '( Oxford Brown lips:1.1)' [] Current Seed:<PHONE_NUMBER>
I'm not sure where it's getting 'hazel' from in the first Adetailer prompt output. It's not just a one-off, either - each time I rerun there's at least one different wildcard thrown into the mix.
If the 0_color and 1_color would lock in the wildcard value anywhere they are used I think this would be solved.

Did you still have the standard wildcards extension installed?
Make sure you have stable-diffusion-webui-wildcards-adetailer installed and disable stable-diffusion-webui-wildcards
The fact it isn't finding the 0_color means that you probably do. Also you don't have the tiers in adetailer, so they just go to color.txt randomly.

Now that I think about it. It might also clash with dynamic prompts.
You could always change text = text.split("__") line in extensions\stable-diffusion-webui-wildcards-adetailer\scripts\wildcards.py to something like text = text.split("~~")
Then the wildcards from my plugin would look like ~~1_wildcard~~
Or use any other character that isn't used for anything else. Just make sure its the same character before and after.

OH - you have to copy all the wildcards to the /wildcards dir in your extension.
Ok, I thought your extension augmented the existing Dynamic Prompts.  I don't have the original wildcards extension active but I do have Dynamic Prompts active, and had all the wildcards in its /wildcards dir.
Yes, I think the extensions are definitely clashing since both use double underscores, so I'll change it to double tildes and continue testing.
thanks!

OH - you have to copy all the wildcards to the /wildcards dir in your extension. Ok, I thought your extension augmented the existing Dynamic Prompts. I don't have the original wildcards extension active but I do have Dynamic Prompts active, and had all the wildcards in its /wildcards dir. Yes, I think the extensions are definitely clashing since both use double underscores, so I'll change it to double tildes and continue testing.
thanks!

yw.
I aint no developer myself, but I was frustrated with this issue too. So I spend a weekend trying to work something out. If I had some more programming knowledge I'd have done it for dynamic prompts. But original wildcards plugin was tiny and easier to understand for me. And now it has all the functionality I personally needed.
PS: You can use --wildcards-dir "D:\wildcards" or to whereever your dynamic prompts wildcards dir is as a cmd flag to let my plugin look for wildcards in that dir instead. So no need for two seperate directories.

Awesome - it's super close to working fully now.
Vastly better than any other fix I've seen or tried.
I had tried applying a fix to Dynamic Prompts a while back as I was learning Python but the way its coded seems to be a bit of a maze with lots of duplicate areas and dead ends. I got a ways in, but not nearly this successful.
Actually, now I think it's working fully.
I'm not sure why, but a couple times the cmd window said it was doing the same ad_prompt again, in which case the seed would increase by 1 and yield a different result.
I'm now testing with 3 different colors spread over the main prompt and 4 Adetailer prompts.
It's only happened twice so far I think.  Instead of doing ad_prompt 1-4 in order it'd repeat the first or second and increase the seed.
Now it seems fine, though - hasn't done it in the last ~20 generations.
Great effort and thanks much for the extension!

Has anyone had any progress on this without requiring a separate fork or old commit of a1111? This is truly a necessary feature to make Adetailer mesh with Dynamic Prompts.

Just use my fork of dynamicprompts and you can use all the variables you define in your main prompt in your ADetailer prompts as well:
https://github.com/Nrgte/dynamicprompts

Ok I'll give that a try, too.
I looked at that before but it sounded like it'd only work with A1111 v1.5.1 , but maybe I read wrong.

Ok I'll give that a try, too. I looked at that before but it sounded like it'd only work with A1111 v1.5.1 , but maybe I read wrong.

That's just the only version I've tested it with, but I assume it works with newer versions too.
You just have to make sure you set the dynamic prompts extension to this version, otherwise it'll download the upstream version of the library:
dynamicprompts[attentiongrabber,magicprompt]~=0.29.0

Hi. Can you update your fork to work with the latest version of forge?

Ok I'll give that a try, too. I looked at that before but it sounded like it'd only work with A1111 v1.5.1 , but maybe I read wrong.

That's just the only version I've tested it with, but I assume it works with newer versions too.
You just have to make sure you set the dynamic prompts extension to this version, otherwise it'll download the upstream version of the library: dynamicprompts[attentiongrabber,magicprompt]~=0.29.0
Edit: just checked, it also works with this version of Forge: f0.0.17v1.8.0rc-latest-276-g29be1da7

Ok I'll give that a try, too. I looked at that before but it sounded like it'd only work with A1111 v1.5.1 , but maybe I read wrong.

That's just the only version I've tested it with, but I assume it works with newer versions too.
You just have to make sure you set the dynamic prompts extension to this version, otherwise it'll download the upstream version of the library: dynamicprompts[attentiongrabber,magicprompt]~=0.29.0
Edit: just checked, it also works with this version of Forge: f0.0.17v1.8.0rc-latest-276-g29be1da7

I couldn't make it with your extension. I guess I used it as described:
Prompt:

Hires:

ADetailer:

This is the result:

I enabled those extensions:

Any ideas, what I'm doing wrong?

Any ideas, what I'm doing wrong?

Do you see something in the console? It's normal that it doesn't get displayed in the prompt window, but it should show the replacement in the console. Otherwise, have you installed my extension according to the instructions and set: dynamicprompts[attentiongrabber,magicprompt]~=0.29.0 ?

I found this in the console before the ADetailer starts:
`*** Error running process: C:\Forge\webui\extensions\sd-dynamic-prompts\scripts\dynamic_prompting.py
Traceback (most recent call last):
File "C:\Forge\webui\modules\scripts.py", line 844, in process
script.process(p, *script_args)
File "C:\Forge\webui\extensions\sd-dynamic-prompts\sd_dynamic_prompts\dynamic_prompting.py", line 480, in process
all_prompts, all_negative_prompts = generate_prompts(
File "C:\Forge\webui\extensions\sd-dynamic-prompts\sd_dynamic_prompts\helpers.py", line 93, in generate_prompts
all_prompts = prompt_generator.generate(prompt, num_prompts, seeds=seeds) or [""]
File "C:\Forge\system\python\lib\site-packages\dynamicprompts\generators\randomprompt.py", line 71, in generate
prompts.append(str(next(iter(gen))))
File "C:\Forge\system\python\lib\site-packages\dynamicprompts\sampling_context.py", line 128, in
gen = (res.whitespace_squashed() for res in gen)
File "C:\Forge\system\python\lib\site-packages\dynamicprompts\samplers\base.py", line 76, in _get_sequence
sub_generators = [context.generator_from_command(c) for c in tokens]
File "C:\Forge\system\python\lib\site-packages\dynamicprompts\samplers\base.py", line 76, in
sub_generators = [context.generator_from_command(c) for c in tokens]
File "C:\Forge\system\python\lib\site-packages\dynamicprompts\sampling_context.py", line 100, in generator_from_command
return samp.generator_from_command(command, ctx)
File "C:\Forge\system\python\lib\site-packages\dynamicprompts\samplers\base.py", line 46, in generator_from_command
return self._get_variable(command, context)
File "C:\Forge\system\python\lib\site-packages\dynamicprompts\samplers\base.py", line 98, in _get_variable
raise KeyError(f"Variable {variable} is not defined in this context")
KeyError: 'Variable eyecolor is not defined in this context'
---`
I also have to say, that I didn't set dynamicprompts[attentiongrabber,magicprompt]~=0.29.0.
Can you describe me, how to do that?

Sure in your extensions\sd-dynamic-prompts folder you have a file named pyproject.toml
You have to edit that, the top lines should look something like this:
dependencies = [
"send2trash~=1.8",
"dynamicprompts[attentiongrabber,magicprompt]~=0.29.0",
]
After you've set this, you have to perform the installation steps of my extension. Otherwise it'll overwrite my extension when you start A1111 / sd-forge.

Sorry, but I can't make it work... I even issued the branch, you mentioned in your Readme.md:
https://github.com/adieyal/sd-dynamic-prompts/commit/39c06b30409df6259c4430338123f7d4e05d8dc1
I have problems to do this installation step:

Delete the existing folder: venv\Lib\site-packages\dynamicprompts

Copy the content of the src\dynamicprompts_ng folder into venv\Lib\site-packages\dynamicprompts

There is no such folder in the Forge-Directory.

So you're not having a venv folder in your forge directory?

No...

I tried to change the variable above to 0 but Forge starts with an error then...

Hmm looks like sd-forge has a new installation method. Check if you have a system\python\Lib\site-packages\dynamicprompts folder?

Yeah, there is such a folder. I replaced the content with your content from src\dynamicprompts_ng and the error is gone.
But it I have still problems to use the variable in the hires. fix. The image is generated with a random color. There is no output in the console.

Go into your extensions\sd-dynamic-prompts folder and make sure the dependencies are like this:
dependencies = [
"send2trash~=1.8",
"dynamicprompts[attentiongrabber,magicprompt]~=0.29.0",
]
Otherwise the folder gets replaced on startup.

It's already set:

Do you have another idea?

What do you mean by you have problem in the high res fix? My fork only makes the variables from the regular prompt available in ADetailer.


Protect /register ?

Hi,
First, thanks for the plugin, it's really helpful.
Second, how can I protect the register route ? I would like to setup a super-admin user by default (like django, I will do it via CLI) and that after, only a logged-in super-admin can register people.
Thanks in advance for the answer.

@frankie567 Any idea ?

Hello!
It's actually pretty easy using the FastAPI ability to add dependencies to a whole router. Since the /register router is available by itself in fastapi-users, you can do something like this:
app.include_router(
    fastapi_users.get_register_router(on_after_register),
    prefix="/auth",
    tags=["auth"],
    dependencies=[Depends(fastapi_users.get_current_superuser)],
)

Cheers!

@frankie567 Thanks, it works.


Fix client resource leaks-issues 8451 and 28153

Fix for https://github.com/grpc/grpc/issues/8451 and https://github.com/grpc/grpc/issues/28153
The same fix is for both the issues above.
Resource leaks were occurring in the client under certain conditions such as an error received (e.g. server unavailable) or call cancelled before all of the response stream read to the end (which is in fact another error condition with the error Cancelled).

@apolcyn for review

@veblush  can you please merge? (branch is locked).
I checked the test failures and they are unrelated to C#.


Packages icons and bumped versions

Icons for packages.

Re-uploaded versions of the icons:

ActiveCampaign: 128x13
emerchantpay: 128x45
HubSpot: 128x37
Zapier: 128x59

Most of the logos were picked from the official logo and marketing pack of the partner and include images that are difficult to bring to 128x128 without looking pixelated.


⚠ Processors has degraded performance

In 6618410, Processors ($STATUS_URL) experienced degraded performance:

HTTP code: 200
Response time: 37 ms

Resolved: Processors performance has improved in fef1311.


Add interface names into NSM metrics

Task: https://github.com/networkservicemesh/sdk-vpp/issues/768
Add interface details for NSE:

Depends on: https://github.com/networkservicemesh/sdk-vpp/pull/771

@NikitaSkrynnik @d-uzlov @denis-tingaikin @glazychev-art @VitalyGushin please review


Histogram estimator correction

Thanks for contributing a pull request!
Please be aware that we are a loose team of volunteers so patience is
necessary. Assistance handling other issues is very welcome. We value
all user contributions, no matter how minor they are. If we are slow to
review, either the pull request needs some benchmarking, tinkering,
convincing, etc. or more likely the reviewers are simply busy. In either
case, we ask for your understanding during the review process.
Again, thanks for contributing!
Reference issue
Example: Fixes #1234.
What does this implement/fix?
Explain your changes.
Additional information
Any additional information you think is important.

Ciao @Mattehub. Can you please describe your pull request please?

Sorry for not describing it @EtienneCmb , I see now that few test are failing. I found that a possible way to estimate entropy by binning a continuous variable is by using the histogram estimator. The way we were doing it before has a bias. This estimator is made in order to avoid that bias. So I implemented the possibility of estimating the entropy using this estimator. Now it is possible to do that automatically by giving in input to the function entropy_bin, the bin_siz. So concretely what changed is:

function entropy_bin allow to give one more input, bin_siz
function digitalize, when use_sklearn = False, give one more output, bin_siz

Important point: do you want I add one more estimator that directly from the continuous data compute the entropy with the histogram estimator? In this case giving "binning", would be the entropy of a discrete variable. With "histogram estimator", it is the entropy of a continuous variable, but with the estimator described above.
PS. On frama I sent some messages about that.

Ok. I propose a few modifications :

the test are failing because the digitize function returns two outputs. If you never use the second one, then I think it's not needed. We can let the function as it was, same for the tests
can you rename for bin_size? It's more explicit

Can you please provide the ressources you used please?

Thanks for the answer! I changed the test so that it worked. The thing is that the histogram estimator, without changing the functions as I did, can not be implemented easily by the users. In my pull request, the aim is that users, by using together the functions we provide, can perform histogram estimation (continuous data -> binning, bin size -> entropy with correction). Another possibility would be that we give another entropy method, in which all these three steps are done automatically, in thi case we can call it "histogram" estimator. In this case, among the possible methods we have: "binning" for discrete data; "histogram" for continuous data, by discretizing it. what do you think about it?
Here two references in which I took the information: document, and wikipedia.
For bin_size, I completely agree! I am changing it.

Hi @EtienneCmb, sorry to write you here. I have a little issue in the changes of the functions. To use digitize within entropy_hist I had to substitute the functions within digitize, from numpy -> jax.numpy. I think this is one of the things that are making the test failing. Before changing more lines, I wanted to make sure that is ok if to have jnp instead of np in the functions within digitize. You can see the details about it in the changes to the file utils.stats
Do you think it is ok?


after an app restores from the background, existing images no longer render

See discussion here: https://github.com/dart-lang/conference_app/pull/43#issuecomment-359641858

run the app
switch to another application
switch back to the app; images in the schedule that were previously loaded now won't render (but the space where they should be will be sized properly); scrolling down will load in previously un-loaded images

This occurs on the head version of flutter, but not for previous versions. /cc @rock3r

I was with this issue too. I just did a flutter upgrade using the master branch and the issue is gone.

I suspect that this issue was for a range of commits on master, and is now addressed.


time scales and formats

I am wondering how I can use time format ( or scale) effectively. Actually I want to output system uptime (seconds since boot) as (days) hh:mm, for example: 4 days, 22:32
I have tried the example included in the README which gives me the following:
var humanFormat = require("human-format");
var timeScale = new humanFormat.Scale({
    seconds: 0,
    minutes: 60,
    hours: 3600,
    days: 86400,
    months: 2592000,
})
console.log(humanFormat(425348, { scale: timeScale }));

which gives me 4.92 days
@julien-f @sweetpi How can I get the desired output format?

@mwittig I don't know. Did you update to the newest versiont? I don't remember this time scales as I've used the module.

@mwittig Sorry for this very late response, it's not possible to have the format you want for now as it is not what this library has been designed for.
The initial intent was to be able to convert bytes to MB/GB/etc., the time scale you can see on the README is just another possible use but is indeed not the most common way to format durations.
You can either check Moment.js which is the reference for handling dates/times in JS or you can submit a PR to this library which suits your need while being also relevant for other scales.
For instance, an option to display n round units (4 days, 22 hours and 22 minutes) instead of a single floating one (4.92 days).

I think you can try https://github.com/jsmreese/moment-duration-format

@Delagen Thanks for your input :)
I'm going to close this issue, as it's old and not really something I want to implement.

Thanks to all for the suggestions, to @Delagen in particular, as moment-duration-format is exactly what I need


Handshaking Failure: TL_invokeWithLayer Timeout(10.000000 s)

2018/05/04 09:52:02 MAIN: load authentication
2018/05/04 09:52:02 [MM<PHONE_NUMBER>] start
2018/05/04 09:52:02 [MM<PHONE_NUMBER>] loadsession of  +86*********
2018/05/04 09:52:02 [0-4060730080273079382] dial TCP to <IP_ADDRESS>:443
2018/05/04 09:52:02 [0-4060730080273079382] send: start
2018/05/04 09:52:02 [0-4060730080273079382] read: start
2018/05/04 09:52:02 [0-4060730080273079382] send *mtproto.ReqInvokeWithLayer: {"Layer":71,"Query":{"type_url":"type.googleapis.com/mtproto.ReqInitConnection","value":"***********************"}}
2018/05/04 09:52:02 [0-4060730080273079382] read: type: <nil>, data: <nil>, err: Server response error: -404
2018/05/04 09:52:02 [0-4060730080273079382] read: unknown error, Server response error: -404. reconnect to <IP_ADDRESS>:443
2018/05/04 09:52:02 [0-4060730080273079382] notify Event, mtproto.refreshSession: {}, to [0xc4200a8120]
2018/05/04 09:52:02 [MM<PHONE_NUMBER>] refreshSession<PHONE_NUMBER>273079382
2018/05/04 09:52:03 [MM<PHONE_NUMBER>] spinlocked. Session(4060730080273079382) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/04 09:52:04 [MM<PHONE_NUMBER>] spinlocked. Session(4060730080273079382) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/04 09:52:05 [MM<PHONE_NUMBER>] spinlocked. Session(4060730080273079382) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/04 09:52:06 [MM<PHONE_NUMBER>] spinlocked. Session(4060730080273079382) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/04 09:52:07 [MM<PHONE_NUMBER>] spinlocked. Session(4060730080273079382) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/04 09:52:08 [MM<PHONE_NUMBER>] spinlocked. Session(4060730080273079382) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/04 09:52:09 [MM<PHONE_NUMBER>] spinlocked. Session(4060730080273079382) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/04 09:52:10 [MM<PHONE_NUMBER>] spinlocked. Session(4060730080273079382) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/04 09:52:11 [MM<PHONE_NUMBER>] spinlocked. Session(4060730080273079382) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/04 09:52:12 [MM<PHONE_NUMBER>] connect failure: Handshaking Failure: TL_invokeWithLayer Timeout(10.000000 s)
2018/05/04 09:52:12 [0-4060730080273079382] send <nil>: null
2018/05/04 09:52:12 [0-4060730080273079382] send <nil>: null
2018/05/04 09:52:12 [0-4060730080273079382] send: stop
2018/05/04 09:52:12 [0-4060730080273079382] read: wait for inner routine ...
2018/05/04 09:52:12 [0-4060730080273079382] read: stop
2018/05/04 09:52:12 [0-4060730080273079382] notify Event, mtproto.SessionDiscarded: {}, to [0xc4200a8120]
2018/05/04 09:52:12 [MM<PHONE_NUMBER>] session discarded<PHONE_NUMBER>273079382

Are you in China? If so, please make sure the server endpoint (<IP_ADDRESS>:443) is reachable from your PC. You can test it using Telenet on Windows and Netcat on Mac/Linux.

Hello.   I am in China .
It is success when I ping to <IP_ADDRESS>   .
I am using VPN.

@Vannnnish ping does not make sure you can reach to the port. It just shows whether the ip is reachable. If you are using Linux/Mac, can you try "nc -vz <IP_ADDRESS> 443"? Please share its result together with your mtproto log as @heroto did.

@cjongseok   Ok,
log:
2018/05/05 18:58:39 [MM 3718131] start
2018/05/05 18:58:39 [MM 3718131] loadsession of  +8617318070950
2018/05/05 18:58:39 [0-945840640502653585] dial TCP to <IP_ADDRESS>:443
2018/05/05 18:58:39 [0-945840640502653585] read: start
2018/05/05 18:58:39 [0-945840640502653585] send: start
2018/05/05 18:58:39 [0-945840640502653585] send *mtproto.ReqInvokeWithLayer: {"Layer":71,"Query":{"type_url":"type.googleapis.com/mtproto.ReqInitConnection","value":"CJySDRIHVW5rbm93bhoMZGFyd2luL2FtZDY0IgUwLjAuMSoCZW46AmVuQi4KLHR5cGUuZ29vZ2xlYXBpcy5jb20vbXRwcm90by5SZXFIZWxwR2V0Q29uZmln"}}
2018/05/05 18:58:40 [0-945840640502653585] read: type: <nil>, data: <nil>, err: EOF
2018/05/05 18:58:40 [0-945840640502653585] read: lost connection (captured EOF). reconnect to <IP_ADDRESS>:443
2018/05/05 18:58:40 [0-945840640502653585] notify Event, mtproto.refreshSession: {}, to [0xc4200be120]
2018/05/05 18:58:40 [MM 3718131] refreshSession<PHONE_NUMBER>02653585
2018/05/05 18:58:41 [MM 3718131] spinlocked. Session(945840640502653585) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/05 18:58:42 [MM 3718131] spinlocked. Session(945840640502653585) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/05 18:58:43 [MM 3718131] spinlocked. Session(945840640502653585) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/05 18:58:44 [MM 3718131] spinlocked. Session(945840640502653585) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/05 18:58:45 [MM 3718131] spinlocked. Session(945840640502653585) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/05 18:58:46 [MM 3718131] spinlocked. Session(945840640502653585) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/05 18:58:47 [MM 3718131] spinlocked. Session(945840640502653585) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/05 18:58:48 [MM 3718131] spinlocked. Session(945840640502653585) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/05 18:58:49 [MM 3718131] spinlocked. Session(945840640502653585) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/05/05 18:58:49 [MM 3718131] connect failure: Handshaking Failure: TL_invokeWithLayer Timeout(10.000000 s)
2018/05/05 18:58:49 [0-945840640502653585] send <nil>: null
2018/05/05 18:58:49 [0-945840640502653585] send <nil>: null
2018/05/05 18:58:49 [0-945840640502653585] send <nil>: null
2018/05/05 18:58:49 [0-945840640502653585] send: stop
2018/05/05 18:58:49 [0-945840640502653585] read: wait for inner routine ...
2018/05/05 18:58:49 [0-945840640502653585] read: stop
2018/05/05 18:58:49 [0-945840640502653585] notify Event, mtproto.SessionDiscarded: {}, to [0xc4200be120]
panic: Handshaking Failure: TL_invokeWithLayer Timeout(10.000000 s)

nc result：
found 0 associations
found 1 connections:
     1: flags=82<CONNECTED,PREFERRED>
        outif utun1
        src <IP_ADDRESS> port 59557
        dst <IP_ADDRESS> port 443
        rank info not available
        TCP aux info available

Connection to <IP_ADDRESS> port 443 [tcp/https] succeeded!

thanks.

@Vannnnish can you check your api_id, api_hash, and, server address are valid in https://my.telegram.org/apps ? And you tried  mtproto/examples/simpleshell?

I signed up use method without key. so I think those api_id ,api_hash ,server address is fine...

@Vannnnish ok, then the error is from mtproto/examples/simpleshell, when you run it with key?

2018/05/05 19:31:14 MAIN: new authentication
2018/05/05 19:31:14 [MM 243010863] start
2018/05/05 19:31:14 [MM 243010863] newsession to  <IP_ADDRESS>:443
2018/05/05 19:31:14 [0-7908473676283906779] dial TCP to <IP_ADDRESS>:443
2018/05/05 19:31:17 [0-7908473676283906779] send: start
2018/05/05 19:31:17 [0-7908473676283906779] read: start
2018/05/05 19:31:17 [0-7908473676283906779] send *mtproto.ReqInvokeWithLayer: {"Layer":71,"Query":{"type_url":"type.googleapis.com/mtproto.ReqInitConnection","value":"CJySDRIHVW5rbm93bhoMZGFyd2luL2FtZDY0IgUwLjAuMSoCZW46AmVuQi4KLHR5cGUuZ29vZ2xlYXBpcy5jb20vbXRwcm90by5SZXFIZWxwR2V0Q29uZmln"}}
2018/05/05 19:31:17 [0-7908473676283906779] read: type: mtproto.TL_msg_container, data: {[{6552057982236821505 1 28 {6552057981229329584<PHONE_NUMBER>917702167 [73 210 102 15 103 114 239 144]}} {6552057982236974081 2 20 {[6552057981229329584]}}]}, err: <nil>
2018/05/05 19:31:17 [0-7908473676283906779] send mtproto.TL_msgs_ack: {}
2018/05/05 19:31:17 [0-7908473676283906779] read: type: mtproto.TL_rpc_result, data: {6552057981229329584 Date:1525519877 Expires:1525523106 TestMode:<BoolFalse:<> > ThisDc:2 DcOptions:<Value:<Id:1 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:1 IpAddress:"2001:0b28:f23d:f001:0000:0000:0000:000a" Port:443 > > DcOptions:<Value:<Id:2 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:16 Id:2 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:2 IpAddress:"2001:067c:04e8:f002:0000:0000:0000:000a" Port:443 > > DcOptions:<Value:<Id:3 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:3 IpAddress:"2001:0b28:f23d:f003:0000:0000:0000:000a" Port:443 > > DcOptions:<Value:<Id:4 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:4 IpAddress:"2001:067c:04e8:f004:0000:0000:0000:000a" Port:443 > > DcOptions:<Value:<Flags:2 Id:4 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Id:5 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:5 IpAddress:"2001:0b28:f23f:f005:0000:0000:0000:000a" Port:443 > > ChatSizeMax:200 MegagroupSizeMax:100000 ForwardedCountMax:100 OnlineUpdatePeriodMs:120000 OfflineBlurTimeoutMs:5000 OfflineIdleTimeoutMs:30000 OnlineCloudTimeoutMs:300000 NotifyCloudDelayMs:30000 NotifyDefaultDelayMs:1500 ChatBigSize:10 PushChatPeriodMs:60000 PushChatLimit:2 SavedGifsLimit:200 EditTimeLimit:172800 RatingEDecay:2419200 StickersRecentLimit:30 StickersFavedLimit:5 PinnedDialogsCountMax:5 CallReceiveTimeoutMs:20000 CallRingTimeoutMs:90000 CallConnectTimeoutMs:30000 CallPacketTimeoutMs:10000 MeUrlPrefix:"https://t.me/" }, err: <nil>
2018/05/05 19:31:17 [0-7908473676283906779] process: unknown data type *mtproto.PredConfig {{"Date":1525519877,"Expires":1525523106,"TestMode":{"Value":{"BoolFalse":{}}},"ThisDc":2,"DcOptions":[{"Value":{"Id":1,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":1,"IpAddress":"2001:0b28:f23d:f001:0000:0000:0000:000a","Port":443}},{"Value":{"Id":2,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":16,"Id":2,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":2,"IpAddress":"2001:067c:04e8:f002:0000:0000:0000:000a","Port":443}},{"Value":{"Id":3,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":3,"IpAddress":"2001:0b28:f23d:f003:0000:0000:0000:000a","Port":443}},{"Value":{"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":4,"IpAddress":"2001:067c:04e8:f004:0000:0000:0000:000a","Port":443}},{"Value":{"Flags":2,"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Id":5,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":5,"IpAddress":"2001:0b28:f23f:f005:0000:0000:0000:000a","Port":443}}],"ChatSizeMax":200,"MegagroupSizeMax":100000,"ForwardedCountMax":100,"OnlineUpdatePeriodMs":120000,"OfflineBlurTimeoutMs":5000,"OfflineIdleTimeoutMs":30000,"OnlineCloudTimeoutMs":300000,"NotifyCloudDelayMs":30000,"NotifyDefaultDelayMs":1500,"ChatBigSize":10,"PushChatPeriodMs":60000,"PushChatLimit":2,"SavedGifsLimit":200,"EditTimeLimit":172800,"RatingEDecay":2419200,"StickersRecentLimit":30,"StickersFavedLimit":5,"PinnedDialogsCountMax":5,"CallReceiveTimeoutMs":20000,"CallRingTimeoutMs":90000,"CallConnectTimeoutMs":30000,"CallPacketTimeoutMs":10000,"MeUrlPrefix":"https://t.me/"}}
2018/05/05 19:31:17 [0-7908473676283906779] config: {"Date":1525519877,"Expires":1525523106,"TestMode":{"Value":{"BoolFalse":{}}},"ThisDc":2,"DcOptions":[{"Value":{"Id":1,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":1,"IpAddress":"2001:0b28:f23d:f001:0000:0000:0000:000a","Port":443}},{"Value":{"Id":2,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":16,"Id":2,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":2,"IpAddress":"2001:067c:04e8:f002:0000:0000:0000:000a","Port":443}},{"Value":{"Id":3,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":3,"IpAddress":"2001:0b28:f23d:f003:0000:0000:0000:000a","Port":443}},{"Value":{"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":4,"IpAddress":"2001:067c:04e8:f004:0000:0000:0000:000a","Port":443}},{"Value":{"Flags":2,"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Id":5,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":5,"IpAddress":"2001:0b28:f23f:f005:0000:0000:0000:000a","Port":443}}],"ChatSizeMax":200,"MegagroupSizeMax":100000,"ForwardedCountMax":100,"OnlineUpdatePeriodMs":120000,"OfflineBlurTimeoutMs":5000,"OfflineIdleTimeoutMs":30000,"OnlineCloudTimeoutMs":300000,"NotifyCloudDelayMs":30000,"NotifyDefaultDelayMs":1500,"ChatBigSize":10,"PushChatPeriodMs":60000,"PushChatLimit":2,"SavedGifsLimit":200,"EditTimeLimit":172800,"RatingEDecay":2419200,"StickersRecentLimit":30,"StickersFavedLimit":5,"PinnedDialogsCountMax":5,"CallReceiveTimeoutMs":20000,"CallRingTimeoutMs":90000,"CallConnectTimeoutMs":30000,"CallPacketTimeoutMs":10000,"MeUrlPrefix":"https://t.me/"}
2018/05/05 19:31:17 [0-7908473676283906779] notify Event, mtproto.SessionEstablished: {}, to [0xc4200ba120]
2018/05/05 19:31:17 [0-7908473676283906779] ping: start
2018/05/05 19:31:17 [MM 243010863] session established<PHONE_NUMBER>283906779
2018/05/05 19:31:17 [mconn 446369967] start
2018/05/05 19:31:17 [mconn 446369967] opened.
2018/05/05 19:31:17 [mconn 446369967] wait for a session binding ...
2018/05/05 19:31:17 [MM 243010863] connectionOpened  446369967
2018/05/05 19:31:17 [mconn 446369967] bind: mconn.discardedUpdatesState is nil
2018/05/05 19:31:17 [MM 243010863] sessionBound: session<PHONE_NUMBER>283906779 is bound to mconn 446369967
2018/05/05 19:31:17 [mconn 446369967] bound to session<PHONE_NUMBER>283906779
2018/05/05 19:31:17 [446369967-7908473676283906779] send mtproto.TL_msgs_ack: {}
2018/05/05 19:31:18 [446369967-7908473676283906779] send *mtproto.ReqAuthSendCode: {"Flags":1,"PhoneNumber":"+8617318070950","CurrentNumber":{"Value":{"BoolTrue":{}}},"ApiId":215324,"ApiHash":"c653edbd702c7883725fd6f45c0dc65d"}
2018/05/05 19:31:18 [446369967-7908473676283906779] read: type: mtproto.TL_rpc_result, data: {6552057986033939032 mtproto RPC error: 303 PHONE_MIGRATE_5}, err: <nil>
2018/05/05 19:31:18 [446369967-7908473676283906779] send mtproto.TL_msgs_ack: {}
2018/05/05 19:31:18 [MM 243010863] renewSession to  <IP_ADDRESS>:443
2018/05/05 19:31:18 [446369967-7908473676283906779] notify Event, mtproto.discardSession: {}, to [0xc4200ba120 0xc42029e0c0]
2018/05/05 19:31:18 [mconn 446369967] session will be discarded7908473676283906779
2018/05/05 19:31:18 [MM 243010863] discard session<PHONE_NUMBER>283906779
2018/05/05 19:31:18 [mconn 446369967] unbound to session<PHONE_NUMBER>283906779
2018/05/05 19:31:18 [MM 243010863] sessionUnbound: session<PHONE_NUMBER>283906779 is unbound from mconn 446369967
2018/05/05 19:31:19 [446369967-7908473676283906779] send: stop
2018/05/05 19:31:19 [446369967-7908473676283906779] read: type: <nil>, data: <nil>, err: read tcp <IP_ADDRESS>:51034-><IP_ADDRESS>:443: use of closed network connection
2018/05/05 19:31:19 [446369967-7908473676283906779] read: TCP connection closed (read tcp <IP_ADDRESS>:51034-><IP_ADDRESS>:443: use of closed network connection)
2018/05/05 19:31:19 [446369967-7908473676283906779] read: wait for inner routine ...
2018/05/05 19:31:19 [446369967-7908473676283906779] read: stop
2018/05/05 19:31:19 [446369967-7908473676283906779] notify Event, mtproto.SessionDiscarded: {}, to [0xc4200ba120 0xc42029e0c0]
2018/05/05 19:31:19 [MM 243010863] session is discarded. keep its updates state, (json): {}
2018/05/05 19:31:19 [MM 243010863] renewRoutine: req newsession
2018/05/05 19:31:19 [MM 243010863] session discarded<PHONE_NUMBER>283906779
2018/05/05 19:31:19 [MM 243010863] newsession to  <IP_ADDRESS>:443
2018/05/05 19:31:19 [0-6157452944715194879] dial TCP to <IP_ADDRESS>:443
2018/05/05 19:31:20 [0-6157452944715194879] send: start
2018/05/05 19:31:20 [0-6157452944715194879] send *mtproto.ReqInvokeWithLayer: {"Layer":71,"Query":{"type_url":"type.googleapis.com/mtproto.ReqInitConnection","value":"CJySDRIHVW5rbm93bhoMZGFyd2luL2FtZDY0IgUwLjAuMSoCZW46AmVuQi4KLHR5cGUuZ29vZ2xlYXBpcy5jb20vbXRwcm90by5SZXFIZWxwR2V0Q29uZmln"}}
2018/05/05 19:31:20 [0-6157452944715194879] read: start
2018/05/05 19:31:20 [0-6157452944715194879] read: type: mtproto.TL_msg_container, data: {[{6552057996693540865 1 28 {6552057994607661740<PHONE_NUMBER>958403107 [243 196 33 19 126 28 169 95]}} {6552057996693583873 2 20 {[6552057994607661740]}}]}, err: <nil>
2018/05/05 19:31:20 [0-6157452944715194879] send mtproto.TL_msgs_ack: {}
2018/05/05 19:31:20 [0-6157452944715194879] read: type: mtproto.TL_rpc_result, data: {6552057994607661740 Date:1525519880 Expires:1525523892 TestMode:<BoolFalse:<> > ThisDc:5 DcOptions:<Value:<Id:1 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:1 IpAddress:"2001:0b28:f23d:f001:0000:0000:0000:000a" Port:443 > > DcOptions:<Value:<Id:2 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:16 Id:2 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:2 IpAddress:"2001:067c:04e8:f002:0000:0000:0000:000a" Port:443 > > DcOptions:<Value:<Id:3 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:3 IpAddress:"2001:0b28:f23d:f003:0000:0000:0000:000a" Port:443 > > DcOptions:<Value:<Id:4 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:4 IpAddress:"2001:067c:04e8:f004:0000:0000:0000:000a" Port:443 > > DcOptions:<Value:<Flags:2 Id:4 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Id:5 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:5 IpAddress:"2001:0b28:f23f:f005:0000:0000:0000:000a" Port:443 > > ChatSizeMax:200 MegagroupSizeMax:100000 ForwardedCountMax:100 OnlineUpdatePeriodMs:120000 OfflineBlurTimeoutMs:5000 OfflineIdleTimeoutMs:30000 OnlineCloudTimeoutMs:300000 NotifyCloudDelayMs:30000 NotifyDefaultDelayMs:1500 ChatBigSize:10 PushChatPeriodMs:60000 PushChatLimit:2 SavedGifsLimit:200 EditTimeLimit:172800 RatingEDecay:2419200 StickersRecentLimit:30 StickersFavedLimit:5 PinnedDialogsCountMax:5 CallReceiveTimeoutMs:20000 CallRingTimeoutMs:90000 CallConnectTimeoutMs:30000 CallPacketTimeoutMs:10000 MeUrlPrefix:"https://t.me/" }, err: <nil>
2018/05/05 19:31:20 [0-6157452944715194879] process: unknown data type *mtproto.PredConfig {{"Date":1525519880,"Expires":1525523892,"TestMode":{"Value":{"BoolFalse":{}}},"ThisDc":5,"DcOptions":[{"Value":{"Id":1,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":1,"IpAddress":"2001:0b28:f23d:f001:0000:0000:0000:000a","Port":443}},{"Value":{"Id":2,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":16,"Id":2,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":2,"IpAddress":"2001:067c:04e8:f002:0000:0000:0000:000a","Port":443}},{"Value":{"Id":3,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":3,"IpAddress":"2001:0b28:f23d:f003:0000:0000:0000:000a","Port":443}},{"Value":{"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":4,"IpAddress":"2001:067c:04e8:f004:0000:0000:0000:000a","Port":443}},{"Value":{"Flags":2,"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Id":5,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":5,"IpAddress":"2001:0b28:f23f:f005:0000:0000:0000:000a","Port":443}}],"ChatSizeMax":200,"MegagroupSizeMax":100000,"ForwardedCountMax":100,"OnlineUpdatePeriodMs":120000,"OfflineBlurTimeoutMs":5000,"OfflineIdleTimeoutMs":30000,"OnlineCloudTimeoutMs":300000,"NotifyCloudDelayMs":30000,"NotifyDefaultDelayMs":1500,"ChatBigSize":10,"PushChatPeriodMs":60000,"PushChatLimit":2,"SavedGifsLimit":200,"EditTimeLimit":172800,"RatingEDecay":2419200,"StickersRecentLimit":30,"StickersFavedLimit":5,"PinnedDialogsCountMax":5,"CallReceiveTimeoutMs":20000,"CallRingTimeoutMs":90000,"CallConnectTimeoutMs":30000,"CallPacketTimeoutMs":10000,"MeUrlPrefix":"https://t.me/"}}
2018/05/05 19:31:20 [0-6157452944715194879] config: {"Date":1525519880,"Expires":1525523892,"TestMode":{"Value":{"BoolFalse":{}}},"ThisDc":5,"DcOptions":[{"Value":{"Id":1,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":1,"IpAddress":"2001:0b28:f23d:f001:0000:0000:0000:000a","Port":443}},{"Value":{"Id":2,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":16,"Id":2,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":2,"IpAddress":"2001:067c:04e8:f002:0000:0000:0000:000a","Port":443}},{"Value":{"Id":3,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":3,"IpAddress":"2001:0b28:f23d:f003:0000:0000:0000:000a","Port":443}},{"Value":{"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":4,"IpAddress":"2001:067c:04e8:f004:0000:0000:0000:000a","Port":443}},{"Value":{"Flags":2,"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Id":5,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":5,"IpAddress":"2001:0b28:f23f:f005:0000:0000:0000:000a","Port":443}}],"ChatSizeMax":200,"MegagroupSizeMax":100000,"ForwardedCountMax":100,"OnlineUpdatePeriodMs":120000,"OfflineBlurTimeoutMs":5000,"OfflineIdleTimeoutMs":30000,"OnlineCloudTimeoutMs":300000,"NotifyCloudDelayMs":30000,"NotifyDefaultDelayMs":1500,"ChatBigSize":10,"PushChatPeriodMs":60000,"PushChatLimit":2,"SavedGifsLimit":200,"EditTimeLimit":172800,"RatingEDecay":2419200,"StickersRecentLimit":30,"StickersFavedLimit":5,"PinnedDialogsCountMax":5,"CallReceiveTimeoutMs":20000,"CallRingTimeoutMs":90000,"CallConnectTimeoutMs":30000,"CallPacketTimeoutMs":10000,"MeUrlPrefix":"https://t.me/"}
2018/05/05 19:31:20 [0-6157452944715194879] notify Event, mtproto.SessionEstablished: {}, to [0xc4200ba120]
2018/05/05 19:31:20 [0-6157452944715194879] ping: start
2018/05/05 19:31:20 [MM 243010863] session established<PHONE_NUMBER>715194879
2018/05/05 19:31:20 [MM 243010863] sessionBound: session<PHONE_NUMBER>715194879 is bound to mconn 446369967
2018/05/05 19:31:20 [MM 243010863] renewSession done
2018/05/05 19:31:20 [mconn 446369967] bound to session<PHONE_NUMBER>715194879
2018/05/05 19:31:21 [446369967-6157452944715194879] send mtproto.TL_msgs_ack: {}
2018/05/05 19:31:21 [446369967-6157452944715194879] send *mtproto.ReqAuthSendCode: {"Flags":1,"PhoneNumber":"+8617318070950","CurrentNumber":{"Value":{"BoolTrue":{}}},"ApiId":215324,"ApiHash":"c653edbd702c7883725fd6f45c0dc65d"}
2018/05/05 19:31:22 [446369967-6157452944715194879] read: type: mtproto.TL_rpc_result, data: {6552058002711034784 mtproto RPC error: 420 FLOOD_WAIT_72962}, err: <nil>
2018/05/05 19:31:22 mtproto RPC error: 420 FLOOD_WAIT_72962

I find I cant sign in now.

go run main.go 215324  c653edbd702c7883725fd6f45c0dc65d  +8617318070950  <IP_ADDRESS>:443

@Vannnnish Oh, for many sendCode tries your api_id is banned for 72962 seconds, which 420 FLOOD_WAIT_72962 means. According to your log, it seems InvokeWithLayer you failed before works now. I have just tried mtproto/examples/simpleshell on an Ubuntu container, and it succeeded.
apt-get update && \
  apt-get install -y git vim golang-go
mkdir /root/ws
export GOPATH=/root/ws

I am sorry. It busy since  last talk.  I was try on docker. I succeeded to log in without  key generate.  Neither log file.

@Vannnnish  I think it should be <IP_ADDRESS>:443 , not <IP_ADDRESS>:443.

@cjongseok I am having this issue as well, when connecting using a preexisting key file/session.  A new login works great.
My output is slightly different, and claiming a -404 ( guessing a 404?)
> 2018/05/13 11:52:12 [0-6864795462405635934] read: type: <nil>, data: <nil>, err: Server response error: -404
> 2018/05/13 11:52:12 [0-6864795462405635934] read: unknown error, Server response error: -404. reconnect to <IP_ADDRESS>:443
> 2018/05/13 11:52:12 [0-6864795462405635934] notify Event, mtproto.refreshSession: {}, to [0xc0420461e0]
> 2018/05/13 11:52:12 [MM<PHONE_NUMBER>] refreshSession<PHONE_NUMBER>405635934
> 2018/05/13 11:52:13 [MM<PHONE_NUMBER>] spinlocked. Session(6864795462405635934) is waiting for a response from either invokeWithLayer or updatesGetState.
> 2018/05/13 11:52:14 [MM<PHONE_NUMBER>] spinlocked. Session(6864795462405635934) is waiting for a response from either invokeWithLayer or updatesGetState.
> 2018/05/13 11:52:15 [MM<PHONE_NUMBER>] spinlocked. Session(6864795462405635934) is waiting for a response from either invokeWithLayer or updatesGetState.
> 2018/05/13 11:52:16 [MM<PHONE_NUMBER>] spinlocked. Session(6864795462405635934) is waiting for a response from either invokeWithLayer or updatesGetState.
> 2018/05/13 11:52:17 [MM<PHONE_NUMBER>] spinlocked. Session(6864795462405635934) is waiting for a response from either invokeWithLayer or updatesGetState.
> 2018/05/13 11:52:18 [MM<PHONE_NUMBER>] spinlocked. Session(6864795462405635934) is waiting for a response from either invokeWithLayer or updatesGetState.
> 2018/05/13 11:52:19 [MM<PHONE_NUMBER>] spinlocked. Session(6864795462405635934) is waiting for a response from either invokeWithLayer or updatesGetState.
> 2018/05/13 11:52:20 [MM<PHONE_NUMBER>] spinlocked. Session(6864795462405635934) is waiting for a response from either invokeWithLayer or updatesGetState.
> 2018/05/13 11:52:21 [MM<PHONE_NUMBER>] spinlocked. Session(6864795462405635934) is waiting for a response from either invokeWithLayer or updatesGetState.
> 2018/05/13 11:52:22 [MM<PHONE_NUMBER>] connect failure: Handshaking Failure: TL_invokeWithLayer Timeout(10.000000 s)
> 2018/05/13 11:52:22 [0-6864795462405635934] send: stop
> 2018/05/13 11:52:22 [0-6864795462405635934] read: wait for inner routine ...
> 2018/05/13 11:52:22 [0-6864795462405635934] read: stop
> 2018/05/13 11:52:22 [0-6864795462405635934] notify Event, mtproto.SessionDiscarded: {}, to [0xc0420461e0]
> Handshaking Failure: TL_invokeWithLayer Timeout(10.000000 s)

If you have any insight, it would be greatly appreciated.

@Reid-Garner thanks for your interest in my code. Finally I found the culprit. In the middle of the log, you can find another server endpoint by the keyword 'newsession to'. In my case, it is  <IP_ADDRESS>:443. Please sign-in to this server with your key file.

Unfortunately that is not the same issue that I am having.   I do have a new session to, but it is the same ip.
One thing I am noticing is that the key.mtproto file is not touched again after the initial phone number entry.  It is not updated after entering the key from telegram to allow access.  Also in the log, the send *mtproto.ReqInvokeWithLayer always has the same value.
I am wondering if this is why it returns a 404.  I have also used the older code which has a keygen tool which does update the key file after successful login, but that too does not work.
I havent spent too much time debugging it yet though, and if i figure it out, will post a pull request.

@Reid-Garner Regarding the code 404, I think I need to let you know 'PHONE_MIGRATE_N' on the initial sign-in without key. In the procedure, mtproto tries its authentication to the the specified server. However, usually the server is not responsible for the authentication on the given phone number, and rejects the authentication with a message 'PHONE_MIGRATE_N'. It means that try the authentication again to the 'N'th server in the server list you received on ReqInvokeWithLayer; the values in ReqInvokeWithLayer are always same and it fetches server list by sending 'ReqHelpGetConfig' as its query. mtproto, then, establishes a new session to the new server endpoint(it is why I commented that you can find out new server endpoint with the keyword 'newsession to'), proceeds the authentication, and stores the new server endpoint  in the key file.
I believed the code 404 would mean that this server is wrong and you need to use the migrated server you used in the authentication. So I made the above commit enforcing to use server endpoint in the key file after the initial sign-in.
In your case, however, it seems the specified server(<IP_ADDRESS>:443) is also responsible for your authentication. If you find something out and send a pull request, it would be great.

This magically started working for me - no code changes.   Gotta love that :(
On a different note, I added functionality to support 2fa via password to the Conn.  Once i clean it up a bit, i will send it your way.

@Reid-Garner Great! 2fa would be awesome. I will look forward to get your signals :)

You are right.  I got the problem because of the wrong IP address.
And now , I have a little question.
How to make the command  "send2c" work?
First I use dialogs get the use information (and channel too).
 "User": {
          "Flags": 1111,
          "Id": *********,
          "AccessHash": ************,
          "FirstName": "韩",
          "LastName": "梅梅",
          "Phone": "**********",
          "Status": {
            "Value": {
              "UserStatusOffline": {
                "WasOnline":<PHONE_NUMBER>
              }
            }

then  I type the Id and AccessHash In .  But I only get this error.
2:28 [1143938212-375701389491128197] read: type: mtproto.TL_rpc_result, data: {6560580356725550124 mtproto RPC error: 400 CHANNEL_INVALID}, err: <nil>
2018/05/28 18:42:28 mtproto RPC error: 400 CHANNEL_INVALID

then , I try to send message to channel. but I don't know which one is the Chan_Hash of the channel.  So I leave it empty . But got the same error.

Chan_Hash is your access key to the channel. You can get it from MessagesGetAllChats() with your RPC caller. It returns all the your chat and channel list with their id and hash.

Hi,
Same error here while testing the example. Looks like I am redirected then I get a 404. Pasting the full log below. P.S. I tested and I can telnet to <IP_ADDRESS>:443, I can send commands to it, looks ok.
Kindest regards,
Daniel
2018/07/09 10:34:52 [MM<PHONE_NUMBER>] start
2018/07/09 10:34:52 [MM<PHONE_NUMBER>] newsession to  <IP_ADDRESS>:443
2018/07/09 10:34:52 [0-8062549060325529908] dial TCP to <IP_ADDRESS>:443
2018/07/09 10:34:53 [0-8062549060325529908] send: start
2018/07/09 10:34:53 [0-8062549060325529908] read: start
2018/07/09 10:34:53 [0-8062549060325529908] send *mtproto.ReqInvokeWithLayer: {"Layer":71,"Query":{"type_url":"type.googleapis.com/mtproto.ReqInitConnection","value":"CP3jExIHVW5rbm93bhoNd2luZG93cy9hbWQ2NCIFMC4wLjEqAmVuOgJlbkIuCix0eXBlLmdvb2dsZWFwaXMuY29tL210cHJvdG8uUmVxSGVscEdldENvbmZpZw=="}}
2018/07/09 10:34:53 [0-8062549060325529908] read: type: mtproto.TL_msg_container, data: {[{6576117600026644481 1 28 {6576117598172250128<PHONE_NUMBER>604354942 [57 24 123 47 38 188 69 177]}} {6576117600026679297 2 20 {[6576117598172250128]}}]}, err:
2018/07/09 10:34:53 [0-8062549060325529908] send mtproto.TL_msgs_ack: {}
2018/07/09 10:34:53 [0-8062549060325529908] read: type: mtproto.TL_rpc_result, data: {6576117598172250128 Date:1531121693 Expires:1531125722 TestMode:<BoolFalse:<> > ThisDc:2 DcOptions:<Value:<Id:1 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:16 Id:1 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:1 IpAddress:"2001:0b28:f23d:f001:0000:0000:0000:000a" Port:443 > > DcOptions:<Value:<Id:2 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:16 Id:2 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:2 IpAddress:"2001:067c:04e8:f002:0000:0000:0000:000a" Port:443 > > DcOptions:<Value:<Id:3 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:16 Id:3 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:3 IpAddress:"2001:0b28:f23d:f003:0000:0000:0000:000a" Port:443 > > DcOptions:<Value:<Id:4 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:16 Id:4 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:1 Id:4 IpAddress:"2001:067c:04e8:f004:0000:0000:0000:000a" Port:443 > > DcOptions:<Value:<Flags:2 Id:4 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Flags:3 Id:4 IpAddress:"2001:067c:04e8:f004:0000:0000:0000:000b" Port:443 > > DcOptions:<Value:<Flags:1 Id:5 IpAddress:"2001:0b28:f23f:f005:0000:0000:0000:000a" Port:443 > > DcOptions:<Value:<Flags:16 Id:5 IpAddress:"<IP_ADDRESS>" Port:443 > > DcOptions:<Value:<Id:5 IpAddress:"<IP_ADDRESS>" Port:443 > > ChatSizeMax:200 MegagroupSizeMax:100000 ForwardedCountMax:100 OnlineUpdatePeriodMs:120000 OfflineBlurTimeoutMs:5000 OfflineIdleTimeoutMs:30000 OnlineCloudTimeoutMs:300000 NotifyCloudDelayMs:30000 NotifyDefaultDelayMs:1500 ChatBigSize:10 PushChatPeriodMs:60000 PushChatLimit:2 SavedGifsLimit:200 EditTimeLimit:172800 RatingEDecay:2419200 StickersRecentLimit:30 StickersFavedLimit:5 PinnedDialogsCountMax:5 CallReceiveTimeoutMs:20000 CallRingTimeoutMs:90000 CallConnectTimeoutMs:30000 CallPacketTimeoutMs:10000 MeUrlPrefix:"https://t.me/" }, err:
2018/07/09 10:34:53 [0-8062549060325529908] process: unknown data type *mtproto.PredConfig {{"Date":1531121693,"Expires":1531125722,"TestMode":{"Value":{"BoolFalse":{}}},"ThisDc":2,"DcOptions":[{"Value":{"Id":1,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":16,"Id":1,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":1,"IpAddress":"2001:0b28:f23d:f001:0000:0000:0000:000a","Port":443}},{"Value":{"Id":2,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":16,"Id":2,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":2,"IpAddress":"2001:067c:04e8:f002:0000:0000:0000:000a","Port":443}},{"Value":{"Id":3,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":16,"Id":3,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":3,"IpAddress":"2001:0b28:f23d:f003:0000:0000:0000:000a","Port":443}},{"Value":{"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":16,"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":4,"IpAddress":"2001:067c:04e8:f004:0000:0000:0000:000a","Port":443}},{"Value":{"Flags":2,"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":3,"Id":4,"IpAddress":"2001:067c:04e8:f004:0000:0000:0000:000b","Port":443}},{"Value":{"Flags":1,"Id":5,"IpAddress":"2001:0b28:f23f:f005:0000:0000:0000:000a","Port":443}},{"Value":{"Flags":16,"Id":5,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Id":5,"IpAddress":"<IP_ADDRESS>","Port":443}}],"ChatSizeMax":200,"MegagroupSizeMax":100000,"ForwardedCountMax":100,"OnlineUpdatePeriodMs":120000,"OfflineBlurTimeoutMs":5000,"OfflineIdleTimeoutMs":30000,"OnlineCloudTimeoutMs":300000,"NotifyCloudDelayMs":30000,"NotifyDefaultDelayMs":1500,"ChatBigSize":10,"PushChatPeriodMs":60000,"PushChatLimit":2,"SavedGifsLimit":200,"EditTimeLimit":172800,"RatingEDecay":2419200,"StickersRecentLimit":30,"StickersFavedLimit":5,"PinnedDialogsCountMax":5,"CallReceiveTimeoutMs":20000,"CallRingTimeoutMs":90000,"CallConnectTimeoutMs":30000,"CallPacketTimeoutMs":10000,"MeUrlPrefix":"https://t.me/"}}
2018/07/09 10:34:53 [0-8062549060325529908] help config: {"Date":1531121693,"Expires":1531125722,"TestMode":{"Value":{"BoolFalse":{}}},"ThisDc":2,"DcOptions":[{"Value":{"Id":1,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":16,"Id":1,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":1,"IpAddress":"2001:0b28:f23d:f001:0000:0000:0000:000a","Port":443}},{"Value":{"Id":2,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":16,"Id":2,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":2,"IpAddress":"2001:067c:04e8:f002:0000:0000:0000:000a","Port":443}},{"Value":{"Id":3,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":16,"Id":3,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":3,"IpAddress":"2001:0b28:f23d:f003:0000:0000:0000:000a","Port":443}},{"Value":{"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":16,"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":1,"Id":4,"IpAddress":"2001:067c:04e8:f004:0000:0000:0000:000a","Port":443}},{"Value":{"Flags":2,"Id":4,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Flags":3,"Id":4,"IpAddress":"2001:067c:04e8:f004:0000:0000:0000:000b","Port":443}},{"Value":{"Flags":1,"Id":5,"IpAddress":"2001:0b28:f23f:f005:0000:0000:0000:000a","Port":443}},{"Value":{"Flags":16,"Id":5,"IpAddress":"<IP_ADDRESS>","Port":443}},{"Value":{"Id":5,"IpAddress":"<IP_ADDRESS>","Port":443}}],"ChatSizeMax":200,"MegagroupSizeMax":100000,"ForwardedCountMax":100,"OnlineUpdatePeriodMs":120000,"OfflineBlurTimeoutMs":5000,"OfflineIdleTimeoutMs":30000,"OnlineCloudTimeoutMs":300000,"NotifyCloudDelayMs":30000,"NotifyDefaultDelayMs":1500,"ChatBigSize":10,"PushChatPeriodMs":60000,"PushChatLimit":2,"SavedGifsLimit":200,"EditTimeLimit":172800,"RatingEDecay":2419200,"StickersRecentLimit":30,"StickersFavedLimit":5,"PinnedDialogsCountMax":5,"CallReceiveTimeoutMs":20000,"CallRingTimeoutMs":90000,"CallConnectTimeoutMs":30000,"CallPacketTimeoutMs":10000,"MeUrlPrefix":"https://t.me/"}
2018/07/09 10:34:53 [0-8062549060325529908] notify Event, mtproto.SessionEstablished: {}, to [0xc042066180]
2018/07/09 10:34:53 [0-8062549060325529908] ping: start
2018/07/09 10:34:53 [MM<PHONE_NUMBER>] connectionOpened  113150738
2018/07/09 10:34:53 [mconn 113150738] start
2018/07/09 10:34:53 [MM<PHONE_NUMBER>] session established<PHONE_NUMBER>325529908
2018/07/09 10:34:53 [MM<PHONE_NUMBER>] sessionBound: session<PHONE_NUMBER>325529908 is bound to mconn 113150738
2018/07/09 10:34:53 [mconn 113150738] bound to session<PHONE_NUMBER>325529908
2018/07/09 10:34:53 [mconn 113150738] opened.
2018/07/09 10:34:53 [mconn 113150738] bind: mconn.discardedUpdatesState is nil
2018/07/09 10:34:53 [mconn 113150738] with session,<PHONE_NUMBER>325529908
2018/07/09 10:34:54 [113150738-8062549060325529908] send mtproto.TL_msgs_ack: {}
2018/07/09 10:34:54 [113150738-8062549060325529908] send *mtproto.ReqAuthSendCode: {"Flags":1,"PhoneNumber":"+40722555555","CurrentNumber":{"Value":{"BoolTrue":{}}},"ApiId":555555,"ApiHash":"xxxxx"}
2018/07/09 10:34:55 [113150738-8062549060325529908] read: type: mtproto.TL_rpc_result, data: {6576117606302181520 mtproto RPC error: 303 PHONE_MIGRATE_4}, err:
2018/07/09 10:34:55 [113150738-8062549060325529908] send mtproto.TL_msgs_ack: {}
2018/07/09 10:34:55 [MM<PHONE_NUMBER>] renewSession to  <IP_ADDRESS>:443
2018/07/09 10:34:55 [113150738-8062549060325529908] notify Event, mtproto.discardSession: {}, to [0xc042066180 0xc0421f8180]
2018/07/09 10:34:55 [mconn 113150738] session(8062549060325529908) will be discarded
2018/07/09 10:34:55 [MM<PHONE_NUMBER>] sessionUnbound: session<PHONE_NUMBER>325529908 is unbound from mconn 113150738
2018/07/09 10:34:55 [MM<PHONE_NUMBER>] discard session<PHONE_NUMBER>325529908
2018/07/09 10:34:55 [mconn 113150738] unbound to session<PHONE_NUMBER>325529908
2018/07/09 10:34:55 [113150738-8062549060325529908] send : null
2018/07/09 10:34:55 [113150738-8062549060325529908] send: stop
2018/07/09 10:34:55 [113150738-8062549060325529908] read: type: , data: , err: read tcp <IP_ADDRESS>:49298-><IP_ADDRESS>:443: use of closed network connection
2018/07/09 10:34:55 [113150738-8062549060325529908] read: TCP connection closed (read tcp <IP_ADDRESS>:49298-><IP_ADDRESS>:443: use of closed network connection)
2018/07/09 10:34:55 [113150738-8062549060325529908] read: wait for inner routine ...
2018/07/09 10:34:55 [113150738-8062549060325529908] read: stop
2018/07/09 10:34:55 [113150738-8062549060325529908] notify Event, mtproto.SessionDiscarded: {}, to [0xc042066180 0xc0421f8180]
2018/07/09 10:34:55 [MM<PHONE_NUMBER>] session is discarded. keep its updates state, (json): {}
2018/07/09 10:34:55 [MM<PHONE_NUMBER>] session discarded<PHONE_NUMBER>325529908
2018/07/09 10:34:55 [MM<PHONE_NUMBER>] renewRoutine: req newsession
2018/07/09 10:34:55 [MM<PHONE_NUMBER>] newsession to  <IP_ADDRESS>:443
2018/07/09 10:34:55 [0-451805864856619249] dial TCP to <IP_ADDRESS>:443

@innovative-sol thanks for your interest in this project. It seems mtproto redirects your session to the wrong server, <IP_ADDRESS>. PHONE_MIGRATE_X means redirect the session to the server whose ID is X. Although the ID of <IP_ADDRESS> is also 4, it seems your session needs to redirect to the different one (I think <IP_ADDRESS>) with the same ID but flag. I will patch it to connect the server with the higher flag now.
If you want to test the different server right away, just change the ip field in your generated credentials file credentials.json to <IP_ADDRESS>, and then run go run examples/simpleshell/main.go credentials.json

Hi,
Thanks a lot for the fast reply! Updated the IP as you suggested and got this:
2018/07/09 11:49:21 [MM<PHONE_NUMBER>] start
2018/07/09 11:49:21 [MM<PHONE_NUMBER>] loadsession of conn  0
2018/07/09 11:49:21 [0-5135375494467832145] dial TCP to <IP_ADDRESS>:443
2018/07/09 11:49:21 [0-5135375494467832145] send: start
2018/07/09 11:49:21 [0-5135375494467832145] send *mtproto.ReqInvokeWithLayer: {"Layer":71,"Query":{"type_url":"type.googleapis.com/mtproto.ReqInitConnection","value":"xxxxxxxxxxxxxxx3bhoNd2luZG93cy9hbWQ2NCIFMC4wLjEqAmVuOgJlbkIuCix0eXBlLmdvb2dsZWFwaXMuY29tL210cHJvdG8uUmVxSGVscEdldENvbmZpZw=="}}
2018/07/09 11:49:21 [0-5135375494467832145] read: start
2018/07/09 11:49:21 [0-5135375494467832145] read: type: , data: , err: Server response error: -404
2018/07/09 11:49:21 [0-5135375494467832145] read: unknown error, Server response error: -404. reconnect to <IP_ADDRESS>:443
2018/07/09 11:49:21 [0-5135375494467832145] notify Event, mtproto.refreshSession: {}, to [0xc042066120]
2018/07/09 11:49:21 [MM<PHONE_NUMBER>] refreshSession<PHONE_NUMBER>467832145
2018/07/09 11:49:22 [MM<PHONE_NUMBER>] spinlocked. Session(5135375494467832145) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 11:49:23 [MM<PHONE_NUMBER>] spinlocked. Session(5135375494467832145) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 11:49:24 [MM<PHONE_NUMBER>] spinlocked. Session(5135375494467832145) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 11:49:25 [MM<PHONE_NUMBER>] spinlocked. Session(5135375494467832145) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 11:49:26 [MM<PHONE_NUMBER>] spinlocked. Session(5135375494467832145) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 11:49:27 [MM<PHONE_NUMBER>] spinlocked. Session(5135375494467832145) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 11:49:28 [MM<PHONE_NUMBER>] spinlocked. Session(5135375494467832145) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 11:49:29 [MM<PHONE_NUMBER>] spinlocked. Session(5135375494467832145) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 11:49:30 [MM<PHONE_NUMBER>] spinlocked. Session(5135375494467832145) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 11:49:31 [MM<PHONE_NUMBER>] connect failure: Handshaking Failure: TL_invokeWithLayer Timeout(10.000000 s)
2018/07/09 11:49:31 [0-5135375494467832145] send: stop
2018/07/09 11:49:31 [0-5135375494467832145] read: wait for inner routine ...
2018/07/09 11:49:31 [0-5135375494467832145] read: stop
2018/07/09 11:49:31 [0-5135375494467832145] notify Event, mtproto.SessionDiscarded: {}, to [0xc042066120]
2018/07/09 11:49:31 [MM<PHONE_NUMBER>] session discarded<PHONE_NUMBER>467832145

@innovative-sol oh no. thanks for the fast try. Can you also try <IP_ADDRESS> whose ID is same but much higher flag(16)? This server is the last one with the same ID.

Tried now! Same result unfortunately...
2018/07/09 12:05:40 [MM 672018069] start
2018/07/09 12:05:40 [MM 672018069] loadsession of conn  0
2018/07/09 12:05:40 [0-5900156025972631235] dial TCP to <IP_ADDRESS>:443
2018/07/09 12:05:40 [0-5900156025972631235] send: start
2018/07/09 12:05:40 [0-5900156025972631235] read: start
2018/07/09 12:05:40 [0-5900156025972631235] send *mtproto.ReqInvokeWithLayer: {"Layer":71,"Query":{"type_url":"type.googleapis.com/mtproto.ReqInitConnection","value":"xxxxxxxxxxxxxxx3bhoNd2luZG93cy9hbWQ2NCIFMC4wLjEqAmVuOgJlbkIuCix0eXBlLmdvb2dsZWFwaXMuY29tL210cHJvdG8uUmVxSGVscEdldENvbmZpZw=="}}
2018/07/09 12:05:40 [0-5900156025972631235] read: type: , data: , err: Server response error: -404
2018/07/09 12:05:40 [0-5900156025972631235] read: unknown error, Server response error: -404. reconnect to <IP_ADDRESS>:443
2018/07/09 12:05:40 [0-5900156025972631235] notify Event, mtproto.refreshSession: {}, to [0xc042066120]
2018/07/09 12:05:40 [MM 672018069] refreshSession<PHONE_NUMBER>972631235
2018/07/09 12:05:41 [MM 672018069] spinlocked. Session(5900156025972631235) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:05:42 [MM 672018069] spinlocked. Session(5900156025972631235) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:05:43 [MM 672018069] spinlocked. Session(5900156025972631235) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:05:44 [MM 672018069] spinlocked. Session(5900156025972631235) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:05:45 [MM 672018069] spinlocked. Session(5900156025972631235) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:05:46 [MM 672018069] spinlocked. Session(5900156025972631235) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:05:47 [MM 672018069] spinlocked. Session(5900156025972631235) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:05:48 [MM 672018069] spinlocked. Session(5900156025972631235) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:05:49 [MM 672018069] spinlocked. Session(5900156025972631235) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:05:50 [MM 672018069] connect failure: Handshaking Failure: TL_invokeWithLayer Timeout(10.000000 s)
2018/07/09 12:05:50 [0-5900156025972631235] send: stop
2018/07/09 12:05:50 [0-5900156025972631235] read: wait for inner routine ...
2018/07/09 12:05:50 [0-5900156025972631235] read: stop
2018/07/09 12:05:50 [0-5900156025972631235] notify Event, mtproto.SessionDiscarded: {}, to [0xc042066120]

@innovative-sol I think the remained option we can try is touching <IP_ADDRESS> and <IP_ADDRESS> again from the scratch. I will let you know when the code is ready.

I just installed Telegram Desktop on my machine. I also tested with the ..92 IP address - same result.
2018/07/09 12:40:15 [MM 81822611] start
2018/07/09 12:40:15 [MM 81822611] loadsession of conn  0
2018/07/09 12:40:15 [0-3611346300878101625] dial TCP to <IP_ADDRESS>:443
2018/07/09 12:40:15 [0-3611346300878101625] send: start
2018/07/09 12:40:15 [0-3611346300878101625] read: start
2018/07/09 12:40:15 [0-3611346300878101625] send *mtproto.ReqInvokeWithLayer: {"Layer":71,"Query":{"type_url":"type.googleapis.com/mtproto.ReqInitConnection","value":"xxxxxxxxxxxxxxx3bhoNd2luZG93cy9hbWQ2NCIFMC4wLjEqAmVuOgJlbkIuCix0eXBlLmdvb2dsZWFwaXMuY29tL210cHJvdG8uUmVxSGVscEdldENvbmZpZw=="}}
2018/07/09 12:40:15 [0-3611346300878101625] read: type: , data: , err: Server response error: -404
2018/07/09 12:40:15 [0-3611346300878101625] read: unknown error, Server response error: -404. reconnect to <IP_ADDRESS>:443
2018/07/09 12:40:15 [0-3611346300878101625] notify Event, mtproto.refreshSession: {}, to [0xc042066120]
2018/07/09 12:40:15 [MM 81822611] refreshSession<PHONE_NUMBER>878101625
2018/07/09 12:40:16 [MM 81822611] spinlocked. Session(3611346300878101625) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:40:17 [MM 81822611] spinlocked. Session(3611346300878101625) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:40:18 [MM 81822611] spinlocked. Session(3611346300878101625) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:40:19 [MM 81822611] spinlocked. Session(3611346300878101625) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:40:20 [MM 81822611] spinlocked. Session(3611346300878101625) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:40:21 [MM 81822611] spinlocked. Session(3611346300878101625) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:40:22 [MM 81822611] spinlocked. Session(3611346300878101625) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:40:23 [MM 81822611] spinlocked. Session(3611346300878101625) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:40:24 [MM 81822611] spinlocked. Session(3611346300878101625) is waiting for a response from either invokeWithLayer or updatesGetState.
2018/07/09 12:40:25 [MM 81822611] connect failure: Handshaking Failure: TL_invokeWithLayer Timeout(10.000000 s)
2018/07/09 12:40:25 [0-3611346300878101625] send : null
2018/07/09 12:40:25 [0-3611346300878101625] send : null
2018/07/09 12:40:25 [0-3611346300878101625] send: stop
2018/07/09 12:40:25 [0-3611346300878101625] read: wait for inner routine ...
2018/07/09 12:40:25 [0-3611346300878101625] read: stop
2018/07/09 12:40:25 [0-3611346300878101625] notify Event, mtproto.SessionDiscarded: {}, to [0xc042066120]
2018/07/09 12:40:25 [MM 81822611] session discarded<PHONE_NUMBER>878101625

@innovative-sol I could notice that the server with flags 0 would be for APIs over HTTPs, because flags mean the sum of below options:
	dcOptionFlagIPv6 = 0 // means 2^0
	dcOptionFlagMediaOnly = 1
	dcOptionFlagTcpOnly = 2
	dcOptionFlagCDN = 3
	dcOptionFlagStatic = 4

So the above commit selects the DC with flags 0. If it does not work you can manually inject the desired flags at session.go:1082 where I commented in the commit. If none of servers work, I guess it would be the issue on the server side.

You tried Telegram Desktop! Thanks :). The Telegram Desktop worked on your machine? The reason why I asked you to try it was to make sure the Telegram servers are working with your machine, because it would also migrate your session to the same DC ID.

Thanks a lot for the fast replies and... congratulations! I can confirm that IT WORKS, I managed to successfully authenticate on a new session! 👍 🥇

@innovative-sol Cool! Then I can merge it to the main branch. Thanks for your participation in this project.