The Prophet ﷺ said, "There is no ghirar in prayer or in greeting."Ahmad said, "What I understand by this is that you should not give the greeting of peace nor have it given to you while in prayer, and that a man should not let his prayer be deficient by leaving it while still in doubt about it."
حدثنا أحمد بن حنبل حدثنا عبد الرحمن بن مهدي عن سفيان عن أبي مالك الأشجعي عن أبي حازم
عن النبي ﷺ قال لا غرار في صلاة ولا تسليم قال أحمد يعني فيما أرى أن لا تسلم ولا يسلم عليك ويغرر الرجل بصلاته فينصرف وهو فيها شاك
Its chain of transmission is daif. Bayhaqi narrated it, 2/261, from the hadith of Abu Dawud through the same route, and it is in Musnad Imam Ahmad, 2/61. Hakim graded it sahih according to the criteria of Muslim, 1/264, and Dhahabi agreed with him.Sufyan Thawri was mentioned earlier at 748, and I did not find an explicit statement that he heard it directly.