That would mean that a journey around a Circle Line[0], arriving where you departed, could have potentially infinite length. In fact, if you don't rule out travelling along the same stretch of rail twice, then any return journey could be of unbounded length despite not covering any net distance. Calculating the "longest train journey" then becomes a question of human endurance/longevity/wealth rather than about geography or transport.
Alternatively, if you measure "the distance travelled along the rail, without double counting" then the longest journey is probably equal to the total length of the installed rail network in Eurasia, which is an interesting statistic and a challenging optimisation problem, but hard to consider as a single journey.
[0] https://en.wikipedia.org/wiki/Circle_Line
[1] https://en.wikipedia.org/wiki/List_of_countries_by_rail_tran...